Report.php 4.7 KB

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