Report.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace catchAdmin\report\controller;
  3. use catcher\base\CatchRequest as Request;
  4. use catcher\CatchResponse;
  5. use catcher\base\CatchController;
  6. use catchAdmin\report\model\Report as ReportModel;
  7. use think\facade\Env;
  8. use think\facade\Db;
  9. class Report extends CatchController
  10. {
  11. protected $reportModel;
  12. public function __construct(ReportModel $reportModel)
  13. {
  14. $this->reportModel = $reportModel;
  15. }
  16. /**
  17. * 首页数量数据
  18. * @param Request $request
  19. */
  20. public function homePageCountData(Request $request)
  21. {
  22. $time1=date('Y-m-d',time());
  23. $time2=date('Y-m-d',time());
  24. $passCount=Db::table('station_passing')->where('date','between',[$time1,$time2])->sum('num');
  25. $start_time = date('Y-m-d 00:00:00',time());
  26. $end_time = date('Y-m-d 23:59:59',time());
  27. // $host= Env::get('oracle.hostname', '127.0.0.1');
  28. // $port= Env::get('oracle.hostport', '1521');
  29. // $instance_name= Env::get('oracle.instance', 'ORCL');
  30. // $username= Env::get('oracle.username', 'root');
  31. // $password= Env::get('oracle.password', 'root');
  32. // $conn = oci_connect($username, $password, $host.':'.$port.'/'.$instance_name,'AL32UTF8');
  33. // if (!$conn) {
  34. // $e = oci_error();
  35. // trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
  36. // }
  37. // $sql='SELECT count(*) as TOTAL FROM DSSC2.W_DW_RF_RECORD WHERE RF_DATE >= to_date(\''. $start_time.'\', \'yyyy-mm-dd hh24:mi:ss\') AND RF_DATE <= to_date(\''.$end_time.'\', \'yyyy-mm-dd hh24:mi:ss\') ORDER BY RF_DATE DESC';
  38. // // 查询并渲染
  39. // $stid = oci_parse($conn, $sql);
  40. // oci_define_by_name($stid, 'TOTAL', $passCount);
  41. // oci_execute($stid);
  42. // oci_fetch($stid);
  43. // oci_free_statement($stid);
  44. // oci_close($conn);
  45. $alarmCount=Db::table('control_alarm')->whereBetweenTime('created_at', $start_time,$end_time)->count();
  46. // $passCount=2000000;
  47. // $alarmCount=26;
  48. $data = array(
  49. 'passCount'=>(string)$passCount,
  50. 'alarmCount'=>(string)$alarmCount,
  51. );
  52. return CatchResponse::success($data);
  53. }
  54. /**
  55. * 基站增长趋势数据
  56. * @param Request $request
  57. */
  58. public function stationGrowthTrendData(Request $request)
  59. {
  60. $data = $this->reportModel->getStationGrowthTrendData() ?: [];
  61. return CatchResponse::success($data);
  62. }
  63. /**
  64. * 用户设备增长趋势数据
  65. * @param Request $request
  66. */
  67. public function deviceGrowthTrendData(Request $request)
  68. {
  69. $data = $this->reportModel->getDeviceGrowthTrendData() ?: [];
  70. return CatchResponse::success($data);
  71. }
  72. /**
  73. * 过车总量统计
  74. * @param Request $request
  75. */
  76. public function vehiclePassingCount(Request $request){
  77. $params=$request->param();
  78. $start_time=strtotime($params['timeRange'][0]);
  79. $end_time=strtotime($params['timeRange'][1]);
  80. $xAxisData=[];
  81. $yAxisData=[];
  82. for($i=$start_time;$i<$end_time+24*3600;$i+=24*3600){
  83. $time1=date('Y-m-d',$i);
  84. // $time2=date('Y-m-d',$i);
  85. $xAxisData[]=date('Y-m-d',$i);
  86. // $cond['RF_DATE']=['timeRange',$time1,$time2];
  87. // $count=queryOracleCount('DSSC2.W_DW_RF_RECORD',$cond);
  88. // $count=mt_rand(0,99999);
  89. $count=Db::table('station_passing')->where('date',$time1)->sum('num');
  90. $yAxisData[]=$count;
  91. }
  92. // var_dump($end_time);
  93. return CatchResponse::success(['xAxisData'=>$xAxisData,'yAxisData'=>$yAxisData]);
  94. }
  95. /**
  96. * 区域过车统计
  97. * @param Request $request
  98. */
  99. public function areaDeviceCollect(Request $request){
  100. $params=$request->param();
  101. $start_time=date('Y-m-d',strtotime($params['timeRange'][0]));
  102. $end_time=date('Y-m-d',strtotime($params['timeRange'][1]));
  103. $xAxisData=[];
  104. $yAxisData=[];
  105. $list=Db::table('station_passing')
  106. ->where('date','between',[$start_time,$end_time])
  107. ->field('address,sum(num) as count')
  108. ->group('address')
  109. ->order('count desc')
  110. ->select()->toArray();
  111. foreach($list as $val){
  112. $xAxisData[]=$val['address'];
  113. $yAxisData[]=$val['count'];
  114. }
  115. // $host= Env::get('oracle.hostname', '127.0.0.1');
  116. // $port= Env::get('oracle.hostport', '1521');
  117. // $instance_name= Env::get('oracle.instance', 'ORCL');
  118. // $username= Env::get('oracle.username', 'root');
  119. // $password= Env::get('oracle.password', 'root');
  120. // $conn = oci_connect('dssc3', 'dssc3', '61.175.203.188:6521/DSSC','AL32UTF8');
  121. // if (!$conn) {
  122. // $e = oci_error();
  123. // trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
  124. // }
  125. // $sql='SELECT a.RF_ID,count(a.RF_FLAGID) num,b.DEVICE_NAME FROM DSSC2.W_DW_RF_RECORD a join DSSC2.ADM_DEV b ON a.RF_ID=b.LOGIN_NAME WHERE RF_DATE >= to_date(\''.$start_time.'\', \'yyyy-mm-dd hh24:mi:ss\') AND RF_DATE <= to_date(\''.$end_time.'\', \'yyyy-mm-dd hh24:mi:ss\') GROUP BY a.RF_ID,b.DEVICE_NAME ORDER BY num desc';
  126. // // var_dump($sql);
  127. // // 查询并渲染
  128. // $stid = oci_parse($conn, $sql);
  129. // $r = oci_execute($stid);
  130. // $rows=[];
  131. // while($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
  132. // $rows[]=$row;
  133. // }
  134. // oci_free_statement($stid);
  135. // foreach($rows as $val){
  136. // $xAxisData[]=$val['DEVICE_NAME'];
  137. // $yAxisData[]=$val['NUM'];
  138. // }
  139. // return $rows;
  140. return CatchResponse::success(['xAxisData'=>$xAxisData,'yAxisData'=>$yAxisData]);
  141. }
  142. }