Report.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. $data = array(
  47. 'passCount'=>(string)$passCount,
  48. 'alarmCount'=>(string)$alarmCount,
  49. );
  50. return CatchResponse::success($data);
  51. }
  52. /**
  53. * 基站增长趋势数据
  54. * @param Request $request
  55. */
  56. public function stationGrowthTrendData(Request $request)
  57. {
  58. $data = $this->reportModel->getStationGrowthTrendData() ?: [];
  59. return CatchResponse::success($data);
  60. }
  61. /**
  62. * 用户设备增长趋势数据
  63. * @param Request $request
  64. */
  65. public function deviceGrowthTrendData(Request $request)
  66. {
  67. $data = $this->reportModel->getDeviceGrowthTrendData() ?: [];
  68. return CatchResponse::success($data);
  69. }
  70. /**
  71. * 过车总量统计
  72. * @param Request $request
  73. */
  74. public function vehiclePassingCount(Request $request){
  75. $params=$request->param();
  76. $start_time=strtotime($params['timeRange'][0]);
  77. $end_time=strtotime($params['timeRange'][1]);
  78. $xAxisData=[];
  79. $yAxisData=[];
  80. for($i=$start_time;$i<$end_time+24*3600;$i+=24*3600){
  81. $time1=date('Y-m-d',$i);
  82. // $time2=date('Y-m-d',$i);
  83. $xAxisData[]=date('Y-m-d',$i);
  84. // $cond['RF_DATE']=['timeRange',$time1,$time2];
  85. // $count=queryOracleCount('DSSC2.W_DW_RF_RECORD',$cond);
  86. // $count=mt_rand(0,99999);
  87. $count=Db::table('station_passing')->where('date',$time1)->sum('num');
  88. $yAxisData[]=$count;
  89. }
  90. // var_dump($end_time);
  91. return CatchResponse::success(['xAxisData'=>$xAxisData,'yAxisData'=>$yAxisData]);
  92. }
  93. /**
  94. * 区域过车统计
  95. * @param Request $request
  96. */
  97. public function areaDeviceCollect(Request $request){
  98. $params=$request->param();
  99. $start_time=date('Y-m-d',strtotime($params['timeRange'][0]));
  100. $end_time=date('Y-m-d',strtotime($params['timeRange'][1]));
  101. $xAxisData=[];
  102. $yAxisData=[];
  103. $list=Db::table('station_passing')
  104. ->where('date','between',[$start_time,$end_time])
  105. ->field('address,sum(num) as count')
  106. ->group('address')
  107. ->order('count desc')
  108. ->select()->toArray();
  109. foreach($list as $val){
  110. $xAxisData[]=$val['address'];
  111. $yAxisData[]=$val['count'];
  112. }
  113. // $host= Env::get('oracle.hostname', '127.0.0.1');
  114. // $port= Env::get('oracle.hostport', '1521');
  115. // $instance_name= Env::get('oracle.instance', 'ORCL');
  116. // $username= Env::get('oracle.username', 'root');
  117. // $password= Env::get('oracle.password', 'root');
  118. // $conn = oci_connect('dssc3', 'dssc3', '61.175.203.188:6521/DSSC','AL32UTF8');
  119. // if (!$conn) {
  120. // $e = oci_error();
  121. // trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
  122. // }
  123. // $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';
  124. // // var_dump($sql);
  125. // // 查询并渲染
  126. // $stid = oci_parse($conn, $sql);
  127. // $r = oci_execute($stid);
  128. // $rows=[];
  129. // while($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
  130. // $rows[]=$row;
  131. // }
  132. // oci_free_statement($stid);
  133. // foreach($rows as $val){
  134. // $xAxisData[]=$val['DEVICE_NAME'];
  135. // $yAxisData[]=$val['NUM'];
  136. // }
  137. // return $rows;
  138. return CatchResponse::success(['xAxisData'=>$xAxisData,'yAxisData'=>$yAxisData]);
  139. }
  140. }