ZQDcsSupportController.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace Modules\OpcData\Http\Controllers\Api\zaoquan;
  3. use App\Http\Controllers\Api\BaseController;
  4. use Illuminate\Contracts\Support\Renderable;
  5. use Illuminate\Routing\Controller;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Http\Request;
  8. use Modules\OpcData\Services\zaoquan\ZQDcsApiService;
  9. /**
  10. * 枣泉自动化——东井通风
  11. */
  12. class ZQDcsSupportController extends BaseController
  13. {
  14. private $db_name='etl_zaoquan';
  15. protected $apiService;
  16. protected $apiUrl = 'http://7.250.4.3:4300/v1/common/GetPointRealDataByPageV3';
  17. public function __construct(ZQDcsApiService $apiService)
  18. {
  19. $this->apiService = $apiService;
  20. }
  21. public function getList(Request $request) {
  22. $sysCode = isset($request->sys_code) ? $request->sys_code : null; // 矿分类
  23. if ($sysCode == null) {
  24. $msg="参数为空";
  25. $code=-1;
  26. return $this->error($code, $msg);
  27. }
  28. switch ($sysCode) {
  29. case 'main':
  30. return $this->getMainSupport();
  31. default:
  32. $msg="未知数据";
  33. $code=-2;
  34. return $this->error($code, $msg);
  35. }
  36. }
  37. /*
  38. * 获取液压支架数据
  39. */
  40. public function getMainSupport() {
  41. $keys=[
  42. "2045462760907777_1","2045462763406337_1","2045462765667329_1","2045462767137793_1",
  43. "2045462768696321_1","2045462770000897_1","2045462771368961_1","2045462772763649_1",
  44. "2045462774033409_1","2045462757030913_1","2045462758366209_1","2045462759554049_1",
  45. "2045462759674881_1","2045462759814145_1","2045462760064001_1","2045462760188929_1",
  46. "2045462760305665_1","2045462760451073_1","2045462760561665_1","2045462761878529_1",
  47. "2045462761995265_1","2045462762161153_1","2045462762314753_1","2045462762451969_1",
  48. "2045462762566657_1","2045462762679297_1","2045462762793985_1","2045462762931201_1",
  49. "2045462763047937_1","2045462764317697_1","2045462764446721_1","2045462764565505_1",
  50. "2045462764680193_1","2045462764798977_1","2045462764911617_1","2045462765034497_1",
  51. "2045462765163521_1","2045462765292545_1","2045462765429761_1","2045462765790209_1",
  52. "2045462765911041_1","2045462766033921_1","2045462766218241_1","2045462766353409_1",
  53. "2045462766523393_1","2045462766646273_1","2045462766773249_1","2045462766896129_1",
  54. "2045462767016961_1","2045462767342593_1","2045462767483905_1","2045462767606785_1",
  55. "2045462767737857_1","2045462767856641_1","2045462767975425_1","2045462768102401_1",
  56. "2045462768251905_1","2045462768403457_1","2045462768528385_1","2045462768811009_1",
  57. "2045462768927745_1","2045462769044481_1","2045462769163265_1","2045462769280001_1",
  58. "2045462769394689_1","2045462769521665_1","2045462769640449_1","2045462769757185_1",
  59. "2045462769880065_1","2045462770115585_1","2045462770269185_1","2045462770390017_1",
  60. "2045462770512897_1","2045462770627585_1","2045462770750465_1","2045462770873345_1",
  61. "2045462771006465_1","2045462771127297_1","2045462771250177_1","2045462771491841_1",
  62. "2045462771610625_1","2045462771729409_1","2045462771842049_1","2045462771956737_1",
  63. "2045462772083713_1","2045462772216833_1","2045462772382721_1","2045462772509697_1",
  64. "2045462772638721_1","2045462772890625_1","2045462773025793_1","2045462773136385_1",
  65. "2045462773242881_1","2045462773363713_1","2045462773472257_1","2045462773582849_1",
  66. "2045462773689345_1","2045462773808129_1","2045462773922817_1","2045462755791873_1",
  67. "2045462755984385_1","2045462756103169_1","2045462756228097_1","2045462756346881_1",
  68. "2045462756457473_1","2045462756572161_1","2045462756690945_1","2045462756803585_1",
  69. "2045462756916225_1","2045462757151745_1","2045462757266433_1","2045462757381121_1",
  70. "2045462757520385_1","2045462757641217_1","2045462757755905_1","2045462757872641_1",
  71. "2045462758013953_1","2045462758126593_1","2045462758241281_1","2045462758478849_1",
  72. "2045462758595585_1","2045462758712321_1","2045462758829057_1","2045462758943745_1",
  73. "2045462759062529_1","2045462759177217_1","2045462759310337_1","2045462759431169_1",
  74. ];
  75. $dataFromGetRequest = $this->apiService->postPointRealData($this->apiUrl, $keys);
  76. if($dataFromGetRequest['data'] == 0) {
  77. $msg = $dataFromGetRequest['Message'];
  78. return $this->error(-1, $msg);
  79. }
  80. $baseData = $dataFromGetRequest['data'];
  81. $support=[];
  82. for ($i = 0; $i < count($keys); $i++) {
  83. $key = $keys[$i];
  84. $support[]=[
  85. "key"=>$key,
  86. "name"=>($i+1)."号立柱压力",
  87. "unit"=>"Mpa",
  88. "val"=> $baseData[$key] ?? 0,
  89. ];
  90. }
  91. $data["sys_point"]=[
  92. "support"=>$support
  93. ];
  94. return json_encode($data);
  95. }
  96. public function getBaseDataArr($tb_name, $data_key) {
  97. $point_id = "'" . implode("','", $data_key) . "'";
  98. // 构建 SQL 查询
  99. $sqlStr = "select `point_id`, `value` from $tb_name where `point_id` in ($point_id)";
  100. $res = $this->executeSql($sqlStr, 1);
  101. $baseData=[];
  102. for ($i = 0; $i < count($res); $i++) {
  103. $key=$res[$i]->point_id;
  104. $val=$res[$i]->value;
  105. $baseData[$key]=$val;
  106. }
  107. return $baseData;
  108. }
  109. public function executeSql($sqlStr, $modelname = -1) {
  110. try{
  111. $opcDB = DB::connection($this->db_name);
  112. $dbResult = $opcDB->select($sqlStr);
  113. return $dbResult;
  114. } catch (\Exception $e) {
  115. switch ($modelname) {
  116. case 1:
  117. return $this->error(-1, '东井通风');
  118. case 2:
  119. return $this->error(-1, '统计日超速出错!');
  120. case 4:
  121. return $this->error(-1, '获取详细列表出错!');
  122. default:
  123. return $this->error(-1, '未知错误!');
  124. }
  125. }
  126. }
  127. }