| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- namespace Modules\OpcData\Http\Controllers\Api;
- use Illuminate\Contracts\Support\Renderable;
- use Illuminate\Http\Request;
- use Illuminate\Routing\Controller;
- use Illuminate\Support\Facades\DB;
- class OpcDataController extends Controller
- {
- /**
- * Display a listing of the resource.
- * @return Renderable
- */
- public function index()
- {
- return view('opcdata::index');
- }
- /**
- * Show the form for creating a new resource.
- * @return Renderable
- */
- public function create()
- {
- return view('opcdata::create');
- }
- /**
- * Store a newly created resource in storage.
- * @param Request $request
- * @return Renderable
- */
- public function store(Request $request)
- {
- //
- }
- /**
- * Show the specified resource.
- * @param int $id
- * @return Renderable
- */
- public function show($id)
- {
- return view('opcdata::show');
- }
- /**
- * Show the form for editing the specified resource.
- * @param int $id
- * @return Renderable
- */
- public function edit($id)
- {
- return view('opcdata::edit');
- }
- /**
- * Update the specified resource in storage.
- * @param Request $request
- * @param int $id
- * @return Renderable
- */
- public function update(Request $request, $id)
- {
- //
- }
- /**
- * Remove the specified resource from storage.
- * @param int $id
- * @return Renderable
- */
- public function destroy($id)
- {
- //
- }
- public function getData()
- {
-
- $db = DB::connection('mysql_opc_jinjiaqu');
- $sqlStr = "
- select t1.fan_type_id,
- t1.fan_type_name,
- t1.device_num,
- t1.device_name,
- case t.val
- when 'True' then 1
- when 'False' then 2
- else t.val
- end val,
- t1.json_key,
- t1.row_number,
- t1.unit
- from `equipment` t
- join tb_fan_dict_list t1 on t.selItem = t1.selItem
- where t1.group_id = 1
- order by t1.fan_type_id, t1.row_number, t1.device_num
- ";
-
- $dbResult = $db->select($sqlStr);
- $dataArr = array();
- foreach ($dbResult as $key => $val) {
- $fanNum = $val->fan_type_id - 1; // 风机号
- $label = $val->device_name; // 设备名
- $devVal = $val->val; // 数值
- $dataType = $val->json_key; // json键值
- $unit = $val->unit;
- $dataArr[$fanNum]['title'] = $val->fan_type_name;
- $valArr = [
- 'label' => $label,
- 'value' => $devVal,
- 'unit' => $unit
- ];
- if($label == '电机') {
- $hisVal = 0;
- if(array_key_exists('state', $dataArr)){
- $hisVal = $dataArr[$fanNum]['state'];
- } else {
- $hisVal = 0;
- };
- $valArr = [
- 'label' => $label,
- 'state' => max($devVal, $hisVal)
- ];
- $dataArr[$fanNum]['state'] = $devVal;
- } else {
- $dataArr[$fanNum][$dataType][] = $valArr;
- }
- }
- return response()->json($dataArr);
- }
- }
|