CarDownCurrLightInfoController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace Modules\OpcData\Http\Controllers\Api;
  3. use App\Http\Controllers\Api\BaseController;
  4. use Illuminate\Contracts\Support\Renderable;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Routing\Controller;
  7. use Illuminate\Support\Facades\DB;
  8. class CarDownCurrLightInfoController extends BaseController
  9. {
  10. public function getList(Request $request) {
  11. $mineCode = isset($request->mine_code) ? $request->mine_code : null; // 矿分类
  12. $carList = $this->getCarInfoList($mineCode);
  13. $dataTotal = $this->getCarCon($mineCode);
  14. $data = [
  15. "total"=>reset($dataTotal[0]),
  16. "list"=>$carList
  17. ];
  18. return json_encode($data);
  19. }
  20. public function getCarCon($mineCode='zaoquan') {
  21. $sqlStr = /** @lang text */
  22. "SELECT count(1) con FROM down_light_status";
  23. return $this->executeSql($sqlStr, 4, $mineCode);
  24. }
  25. // 当前信息详情
  26. public function getCarInfoList($mineCode='zaoquan', $page=0, $perPage = 15) {
  27. if ($mineCode == null) return null;
  28. $sqlStr = /** @lang text */
  29. "SELECT t1.light_name,
  30. case when t.val = 0 then '未知'
  31. when t.val = 1 then '故障'
  32. when t.val = 2 then '自动红灯'
  33. when t.val = 3 then '自动绿灯'
  34. when t.val = 4 then '手动红灯'
  35. when t.val = 5 then '手动绿灯'
  36. when t.val = 6 then '直行绿灯'
  37. when t.val = 7 then '左行绿灯'
  38. when t.val = 8 then '右行绿灯'
  39. when t.val = 9 then '直行左绿灯'
  40. when t.val = 10 then '直行右绿灯'
  41. when t.val = 11 then '左行右绿灯'
  42. end light_state,
  43. case when t.val = 0 then '未知'
  44. when t.val = 1 then '故障'
  45. when t.val = 2 then '红灯'
  46. when t.val = 3 then '绿灯'
  47. when t.val = 4 then '红灯'
  48. when t.val = 5 then '绿灯'
  49. when t.val = 6 then '直行绿灯'
  50. when t.val = 7 then '左行绿灯'
  51. when t.val = 8 then '右行绿灯'
  52. when t.val = 9 then '直行左绿灯'
  53. when t.val = 10 then '直行右绿灯'
  54. when t.val = 11 then '左行右绿灯'
  55. end light_easy_state,
  56. val,
  57. case when t1.light_name regexp '上' then '上行'
  58. when t1.light_name regexp '下' then '下行'
  59. else '未知'
  60. end direction
  61. FROM down_light_status t
  62. left join down_light_info t1 on t.light_num = t1.light_num";
  63. $dbResult = $this->executeSql($sqlStr, 4, $mineCode);
  64. for($i = 0; $i<count($dbResult); $i++) {
  65. $val = $dbResult[$i];
  66. $data[] = [
  67. 'light_name' => $val->light_name,
  68. 'light_state' => $val->light_easy_state,
  69. 'val' => $val->val,
  70. 'direction' => $val->direction
  71. ];
  72. }
  73. return $data ?? null;
  74. }
  75. public function executeSql($sqlStr, $modelname = -1, $mineCode='zaoquan') {
  76. $conn = 'etl_'.$mineCode;
  77. try{
  78. $opcDB = DB::connection($conn);
  79. $dbResult = $opcDB->select($sqlStr);
  80. return $dbResult;
  81. } catch (\Exception $e) {
  82. switch ($modelname) {
  83. case 1:
  84. return $this->error(-1, '统计超速数量出错!');
  85. case 2:
  86. return $this->error(-1, '统计日超速出错!');
  87. case 4:
  88. return $this->error(-1, '获取详细列表出错!');
  89. default:
  90. return $this->error(-1, '未知错误!');
  91. }
  92. }
  93. }
  94. }