|
@@ -0,0 +1,111 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace Modules\OpcData\Http\Controllers\Api;
|
|
|
+
|
|
|
+use App\Http\Controllers\Api\BaseController;
|
|
|
+use Illuminate\Contracts\Support\Renderable;
|
|
|
+use Illuminate\Http\Request;
|
|
|
+use Illuminate\Routing\Controller;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
+
|
|
|
+class CarDownCurrLightInfoController extends BaseController
|
|
|
+{
|
|
|
+ public function getList(Request $request) {
|
|
|
+ $mineCode = isset($request->mine_code) ? $request->mine_code : null; // 矿分类
|
|
|
+ $carList = $this->getCarInfoList($mineCode);
|
|
|
+
|
|
|
+ $dataTotal = $this->getCarCon($mineCode);
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ "total"=>reset($dataTotal[0]),
|
|
|
+ "list"=>$carList
|
|
|
+ ];
|
|
|
+ return json_encode($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getCarCon($mineCode='zaoquan') {
|
|
|
+ $sqlStr = /** @lang text */
|
|
|
+ "SELECT count(1) con FROM down_light_status";
|
|
|
+
|
|
|
+ return $this->executeSql($sqlStr, 4, $mineCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 当前信息详情
|
|
|
+ public function getCarInfoList($mineCode='zaoquan', $page=0, $perPage = 15) {
|
|
|
+
|
|
|
+ if ($mineCode == null) return null;
|
|
|
+
|
|
|
+ $sqlStr = /** @lang text */
|
|
|
+ "SELECT t1.light_name,
|
|
|
+ case when t.val = 0 then '未知'
|
|
|
+ when t.val = 1 then '故障'
|
|
|
+ when t.val = 2 then '自动红灯'
|
|
|
+ when t.val = 3 then '自动绿灯'
|
|
|
+ when t.val = 4 then '手动红灯'
|
|
|
+ when t.val = 5 then '手动绿灯'
|
|
|
+ when t.val = 6 then '直行绿灯'
|
|
|
+ when t.val = 7 then '左行绿灯'
|
|
|
+ when t.val = 8 then '右行绿灯'
|
|
|
+ when t.val = 9 then '直行左绿灯'
|
|
|
+ when t.val = 10 then '直行右绿灯'
|
|
|
+ when t.val = 11 then '左行右绿灯'
|
|
|
+ end light_state,
|
|
|
+ case when t.val = 0 then '未知'
|
|
|
+ when t.val = 1 then '故障'
|
|
|
+ when t.val = 2 then '红灯'
|
|
|
+ when t.val = 3 then '绿灯'
|
|
|
+ when t.val = 4 then '红灯'
|
|
|
+ when t.val = 5 then '绿灯'
|
|
|
+ when t.val = 6 then '直行绿灯'
|
|
|
+ when t.val = 7 then '左行绿灯'
|
|
|
+ when t.val = 8 then '右行绿灯'
|
|
|
+ when t.val = 9 then '直行左绿灯'
|
|
|
+ when t.val = 10 then '直行右绿灯'
|
|
|
+ when t.val = 11 then '左行右绿灯'
|
|
|
+ end light_easy_state,
|
|
|
+ val,
|
|
|
+ case when t1.light_name regexp '上' then '上行'
|
|
|
+ when t1.light_name regexp '下' then '下行'
|
|
|
+ else '未知'
|
|
|
+ end direction
|
|
|
+ FROM down_light_status t
|
|
|
+ left join down_light_info t1 on t.light_num = t1.light_num";
|
|
|
+
|
|
|
+ $dbResult = $this->executeSql($sqlStr, 4, $mineCode);
|
|
|
+
|
|
|
+ for($i = 0; $i<count($dbResult); $i++) {
|
|
|
+ $val = $dbResult[$i];
|
|
|
+ $data[] = [
|
|
|
+ 'light_name' => $val->light_name,
|
|
|
+ 'light_state' => $val->light_easy_state,
|
|
|
+ 'val' => $val->val,
|
|
|
+ 'direction' => $val->direction
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ return $data ?? null;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function executeSql($sqlStr, $modelname = -1, $mineCode='zaoquan') {
|
|
|
+
|
|
|
+ $conn = 'etl_'.$mineCode;
|
|
|
+
|
|
|
+ try{
|
|
|
+ $opcDB = DB::connection($conn);
|
|
|
+ $dbResult = $opcDB->select($sqlStr);
|
|
|
+ return $dbResult;
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ switch ($modelname) {
|
|
|
+ case 1:
|
|
|
+ return $this->error(-1, '统计超速数量出错!');
|
|
|
+ case 2:
|
|
|
+ return $this->error(-1, '统计日超速出错!');
|
|
|
+ case 4:
|
|
|
+ return $this->error(-1, '获取详细列表出错!');
|
|
|
+ default:
|
|
|
+ return $this->error(-1, '未知错误!');
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|