| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- namespace Modules\OpcData\Http\Controllers\Api\zaoquan;
- use App\Http\Controllers\Api\BaseController;
- use Illuminate\Contracts\Support\Renderable;
- use Illuminate\Routing\Controller;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Http\Request;
- use Modules\OpcData\Services\zaoquan\ZQDcsApiService;
- /**
- * 枣泉自动化——东井通风
- */
- class ZQDcsSupportController extends BaseController
- {
- private $db_name='etl_zaoquan';
- protected $apiService;
- protected $apiUrl = 'http://zdh.zaoquan.nxjiewei.com:8011/v1/common/GetPointRealDataByPageV3';
- public function __construct(ZQDcsApiService $apiService)
- {
- $this->apiService = $apiService;
- }
- public function getList(Request $request) {
- $sysCode = isset($request->sys_code) ? $request->sys_code : null; // 矿分类
- if ($sysCode == null) {
- $msg="参数为空";
- $code=-1;
- return $this->error($code, $msg);
- }
- switch ($sysCode) {
- case 'main':
- return $this->getMainSupport();
- default:
- $msg="未知数据";
- $code=-2;
- return $this->error($code, $msg);
- }
- }
- /*
- * 获取液压支架数据
- */
- public function getMainSupport() {
- $keys=[
- "2045462760907777_1","2045462763406337_1","2045462765667329_1","2045462767137793_1",
- "2045462768696321_1","2045462770000897_1","2045462771368961_1","2045462772763649_1",
- "2045462774033409_1","2045462757030913_1","2045462758366209_1","2045462759554049_1",
- "2045462759674881_1","2045462759814145_1","2045462760064001_1","2045462760188929_1",
- "2045462760305665_1","2045462760451073_1","2045462760561665_1","2045462761878529_1",
- "2045462761995265_1","2045462762161153_1","2045462762314753_1","2045462762451969_1",
- "2045462762566657_1","2045462762679297_1","2045462762793985_1","2045462762931201_1",
- "2045462763047937_1","2045462764317697_1","2045462764446721_1","2045462764565505_1",
- "2045462764680193_1","2045462764798977_1","2045462764911617_1","2045462765034497_1",
- "2045462765163521_1","2045462765292545_1","2045462765429761_1","2045462765790209_1",
- "2045462765911041_1","2045462766033921_1","2045462766218241_1","2045462766353409_1",
- "2045462766523393_1","2045462766646273_1","2045462766773249_1","2045462766896129_1",
- "2045462767016961_1","2045462767342593_1","2045462767483905_1","2045462767606785_1",
- "2045462767737857_1","2045462767856641_1","2045462767975425_1","2045462768102401_1",
- "2045462768251905_1","2045462768403457_1","2045462768528385_1","2045462768811009_1",
- "2045462768927745_1","2045462769044481_1","2045462769163265_1","2045462769280001_1",
- "2045462769394689_1","2045462769521665_1","2045462769640449_1","2045462769757185_1",
- "2045462769880065_1","2045462770115585_1","2045462770269185_1","2045462770390017_1",
- "2045462770512897_1","2045462770627585_1","2045462770750465_1","2045462770873345_1",
- "2045462771006465_1","2045462771127297_1","2045462771250177_1","2045462771491841_1",
- "2045462771610625_1","2045462771729409_1","2045462771842049_1","2045462771956737_1",
- "2045462772083713_1","2045462772216833_1","2045462772382721_1","2045462772509697_1",
- "2045462772638721_1","2045462772890625_1","2045462773025793_1","2045462773136385_1",
- "2045462773242881_1","2045462773363713_1","2045462773472257_1","2045462773582849_1",
- "2045462773689345_1","2045462773808129_1","2045462773922817_1","2045462755791873_1",
- "2045462755984385_1","2045462756103169_1","2045462756228097_1","2045462756346881_1",
- "2045462756457473_1","2045462756572161_1","2045462756690945_1","2045462756803585_1",
- "2045462756916225_1","2045462757151745_1","2045462757266433_1","2045462757381121_1",
- "2045462757520385_1","2045462757641217_1","2045462757755905_1","2045462757872641_1",
- "2045462758013953_1","2045462758126593_1","2045462758241281_1","2045462758478849_1",
- "2045462758595585_1","2045462758712321_1","2045462758829057_1","2045462758943745_1",
- "2045462759062529_1","2045462759177217_1","2045462759310337_1","2045462759431169_1",
- ];
- $dataFromGetRequest = $this->apiService->postPointRealData($this->apiUrl, $keys);
- if($dataFromGetRequest['data'] == 0) {
- $msg = $dataFromGetRequest['Message'];
- return $this->error(-1, $msg);
- }
- $baseData = $dataFromGetRequest['data'];
- $support=[];
- for ($i = 0; $i < count($keys); $i++) {
- $key = $keys[$i];
- $support[]=[
- "key"=>$key,
- "name"=>($i+1)."号立柱压力",
- "unit"=>"Mpa",
- "val"=> $baseData[$key] ?? 0,
- ];
- }
- $data["sys_point"]=[
- "support"=>$support
- ];
- return json_encode($data);
- }
- public function getBaseDataArr($tb_name, $data_key) {
- $point_id = "'" . implode("','", $data_key) . "'";
- // 构建 SQL 查询
- $sqlStr = "select `point_id`, `value` from $tb_name where `point_id` in ($point_id)";
- $res = $this->executeSql($sqlStr, 1);
- $baseData=[];
- for ($i = 0; $i < count($res); $i++) {
- $key=$res[$i]->point_id;
- $val=$res[$i]->value;
- $baseData[$key]=$val;
- }
- return $baseData;
- }
- public function executeSql($sqlStr, $modelname = -1) {
- try{
- $opcDB = DB::connection($this->db_name);
- $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, '未知错误!');
- }
- }
- }
- }
|