ZQDcsSupportController.php 5.7 KB

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