CameraApiController.php 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: qiuzijian
  5. * Date: 2021-04-25
  6. * Time: 09:53
  7. */
  8. namespace Modules\Camera\Http\Controllers\Api;
  9. use App\Enum\ApiEnum;
  10. use App\Http\Controllers\Api\BaseController;
  11. use Illuminate\Http\Request;
  12. use Illuminate\Support\Facades\Config;
  13. use Illuminate\Support\Facades\Input;
  14. use Illuminate\Support\Facades\Log;
  15. use Modules\Camera\Entities\CameraList;
  16. use Modules\Camera\Enum\CameraEnum;
  17. use Modules\Camera\Http\Controllers\Api\TdwyController;
  18. use Modules\Camera\Services\CameraServices;
  19. use Modules\Mine\Entities\MineList;
  20. use Modules\Mine\Entities\MineListExt;
  21. use DB;
  22. use OSS\OssClient;
  23. class CameraApiController extends BaseController
  24. {
  25. //通过摄像头类型获取摄像头
  26. public function getCameraByType(){
  27. $mine_code = Input::get('mine_code', '');
  28. $camera_type = Input::get('camera_type', '');
  29. if (!$mine_code || !$camera_type) {
  30. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  31. }
  32. $result['status'] = true;
  33. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  34. $mine = DB::table('mine_list')->where('slug','like','%'.$mine_code.'%')->where('parent_id',0)->where('deleted_at',null)->first();
  35. if (!$mine) {
  36. $result['status'] = false;
  37. $result['msg'] = '矿区名称不存在';
  38. return $result;
  39. }
  40. $mine_list = DB::table('mine_list')->where('degree', 'like', $mine->id . '|' . '%')->where('deleted_at',null)->get();
  41. $mine_array = [];
  42. foreach($mine_list as $k=>$v){
  43. $mine_array[] = $v->id;
  44. }
  45. $query = CameraList::where('is_show', CameraEnum::IS_SHOW_YES)->where('deleted_at',null)->whereIn('mine_id',$mine_array)->where('camera_type',$camera_type)->orderBy('sort', 'desc')->get();
  46. if (!$query) {
  47. $result['status'] = false;
  48. $result['msg'] = '矿区下没有摄像头';
  49. return $result;
  50. }
  51. $result = [];
  52. foreach($query as $k=>$v){
  53. $result[$k]['id'] = $v->id;
  54. $result[$k]['mine_id'] = $v->mine_id;
  55. $result[$k]['camera_name'] = $v->camera_name;
  56. $result[$k]['cover_picture'] = $v->cover_picture;
  57. $result[$k]['camera_status'] = $v->camera_status;
  58. $result[$k]['playback'] = $v->playback;
  59. }
  60. return self::successResponse($result);
  61. }
  62. //宁煤摄像头统计
  63. public function getTotalNingmei(){
  64. $result['status'] = true;
  65. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  66. //宁煤集团
  67. $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
  68. $ydjk = DB::table('mine_list')->where('title','移动监控')->where('deleted_at',null)->get();
  69. $ydjk_list = [];
  70. if(count($ydjk) > 0){
  71. for($i=0;$i<count($ydjk);$i++){
  72. array_push($ydjk_list,$ydjk[$i]->id);
  73. }
  74. }
  75. $ydjk_son = DB::table('mine_list')->whereIn('parent_id',$ydjk_list)->where('deleted_at',null)->get();
  76. if(count($ydjk_son) > 0){
  77. for($i=0;$i<count($ydjk_son);$i++){
  78. array_push($ydjk_list,$ydjk_son[$i]->id);
  79. }
  80. }
  81. $mine_all = DB::table('mine_list')->where('deleted_at',null)->whereNotIn('id',$ydjk_list)->get();//所有区域
  82. $mine_ningmei = [];//宁煤集团所有区域
  83. foreach($mine_all as $k=>$v){
  84. if(explode('|',$v->degree)[0] == $ningmei[0]->id){
  85. $mine_ningmei[] = $v->id;
  86. }
  87. }
  88. //宁煤在离线数量
  89. $data[0]['title'] = '宁煤公司';
  90. $data[0]['mine_code'] = $ningmei[0]->slug;
  91. $data[0]['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('deleted_at',null)->count();
  92. $data[0]['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('camera_status',1)->where('deleted_at',null)->count();
  93. $data[0]['total_offline'] = $data[0]['total'] - $data[0]['total_online'];
  94. $data[0]['rate'] = round($data[0]['total_online'] / $data[0]['total'] * 100,2)."%";
  95. //宁煤下各矿在离线数量
  96. $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('deleted_at',null)->get();
  97. foreach($mine_list as $k => $v){
  98. $mine_use = [];//宁煤下每个矿所有区域
  99. foreach($mine_all as $key=>$value){
  100. if(count(explode('|',$value->degree)) > 1){
  101. if(explode('|',$value->degree)[0] == $ningmei[0]->id && explode('|',$value->degree)[1] == $v->id){
  102. $mine_use[] = $value->id;
  103. }
  104. }
  105. }
  106. $total = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('deleted_at',null)->count();
  107. $total_online = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('camera_status',1)->where('deleted_at',null)->count();
  108. if($total == 0){
  109. $rate = "0%";
  110. }else{
  111. $rate = round($total_online / $total * 100,2)."%";
  112. }
  113. if($v->slug == 'NingXiaMeiYeTeShuZuoYeJianKongShiPin'){
  114. $res['title'] = $v->title;
  115. $res['mine_code'] = $v->slug."_jituan";
  116. $res['total'] = $total;
  117. $res['total_online'] = $total_online;
  118. $res['total_offline'] = $total - $total_online;
  119. $res['rate'] = $rate;
  120. }else{
  121. if($v->slug == 'ShuiDianFenGongSi'){
  122. $v->title = '供电分公司';
  123. }
  124. array_push($data,[
  125. 'title'=>$v->title,
  126. 'mine_code'=>$v->slug."_jituan",
  127. 'total'=>$total,
  128. 'total_online'=>$total_online,
  129. 'total_offline'=>$total - $total_online,
  130. 'rate'=>$rate
  131. ]);
  132. }
  133. }
  134. if(isset($res)){
  135. array_push($data,[
  136. 'title'=>$res['title'],
  137. 'mine_code'=>$res['mine_code'],
  138. 'total'=>$res['total'],
  139. 'total_online'=>$res['total_online'],
  140. 'total_offline'=>$res['total_offline'],
  141. 'rate'=>$res['rate']
  142. ]);
  143. }
  144. return self::successResponse($data);
  145. }
  146. //宁煤摄像头统计字符串
  147. public function getTotalString(){
  148. $result['status'] = true;
  149. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  150. //宁煤集团
  151. $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
  152. $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
  153. $mine_ningmei = [];//宁煤集团所有区域
  154. foreach($mine_all as $k=>$v){
  155. if(explode('|',$v->degree)[0] == $ningmei[0]->id){
  156. $mine_ningmei[] = $v->id;
  157. }
  158. }
  159. //宁煤在离线数量
  160. $nm['title'] = '宁煤公司';
  161. $nm['mine_code'] = $ningmei[0]->slug;
  162. $nm['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('deleted_at',null)->count();
  163. $nm['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('camera_status',1)->where('deleted_at',null)->count();
  164. $nm['total_offline'] = $nm['total'] - $nm['total_online'];
  165. $nm['rate'] = round($nm['total_online'] / $nm['total'] * 100,2);
  166. $data = [];
  167. //宁煤下各矿在离线数量
  168. $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('deleted_at',null)->get();
  169. foreach($mine_list as $k => $v){
  170. $mine_use = [];//宁煤下每个矿所有区域
  171. foreach($mine_all as $key=>$value){
  172. if(count(explode('|',$value->degree)) > 1){
  173. if(explode('|',$value->degree)[0] == $ningmei[0]->id && explode('|',$value->degree)[1] == $v->id){
  174. $mine_use[] = $value->id;
  175. }
  176. }
  177. }
  178. $total = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('deleted_at',null)->count();
  179. $total_online = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('camera_status',1)->where('deleted_at',null)->count();
  180. if($total == 0){
  181. $rate = "0";
  182. }else{
  183. $rate = round($total_online / $total * 100,2);
  184. }
  185. if($v->slug == 'NingXiaMeiYeTeShuZuoYeJianKongShiPin'){
  186. $res['title'] = $v->title;
  187. $res['mine_code'] = $v->slug."_jituan";
  188. $res['total'] = $total;
  189. $res['total_online'] = $total_online;
  190. $res['total_offline'] = $total - $total_online;
  191. $res['rate'] = $rate;
  192. }else{
  193. array_push($data,[
  194. 'title'=>$v->title,
  195. 'mine_code'=>$v->slug."_jituan",
  196. 'total'=>$total,
  197. 'total_online'=>$total_online,
  198. 'total_offline'=>$total - $total_online,
  199. 'rate'=>$rate
  200. ]);
  201. }
  202. }
  203. if(isset($res)){
  204. array_push($data,[
  205. 'title'=>$res['title'],
  206. 'mine_code'=>$res['mine_code'],
  207. 'total'=>$res['total'],
  208. 'total_online'=>$res['total_online'],
  209. 'total_offline'=>$res['total_offline'],
  210. 'rate'=>$res['rate']
  211. ]);
  212. }
  213. $timestamp = strtotime(date('Y-m-d H:i:s'));
  214. $hour = date('G', $timestamp);
  215. $minute = date('i', $timestamp);
  216. $month = date('n', $timestamp);
  217. $day = date('j', $timestamp);
  218. if($minute == '00'){
  219. $minute = '';
  220. }
  221. if ($hour < 12) {
  222. $time = $month."月".$day."号上午".$hour."时".$minute;
  223. } elseif ($hour >= 12 && $hour < 18) {
  224. $time = $month."月".$day."号下午".$hour."时".$minute;
  225. } else {
  226. $time = $month."月".$day."号晚上".$hour."时".$minute;
  227. }
  228. $unit_max_name = '';
  229. $unit_max_rate = 0;
  230. $unit_min_name = '';
  231. $unit_min_rate = 100;
  232. $mzy_max_name = '';
  233. $mzy_max_rate = 0;
  234. $mzy_min_name = '';
  235. $mzy_min_rate = 100;
  236. $other_max_name = '';
  237. $other_max_rate = 0;
  238. $other_min_name = '';
  239. $other_min_rate = 100;
  240. if(count($data)>0){
  241. for($i=0;$i<count($data);$i++){
  242. if (strpos($data[$i]['title'], '煤矿') !== false || strpos($data[$i]['title'], '洗选') !== false) {
  243. if($data[$i]['rate'] > $unit_max_rate){
  244. $unit_max_rate = $data[$i]['rate'];
  245. }
  246. if($data[$i]['rate'] < $unit_min_rate){
  247. $unit_min_rate = $data[$i]['rate'];
  248. }
  249. }elseif(strpos($data[$i]['title'], '煤制油') !== false || strpos($data[$i]['title'], '烯烃') !== false || strpos($data[$i]['title'], '甲醇') !== false || strpos($data[$i]['title'], '精蜡') !== false){
  250. if($data[$i]['rate'] > $mzy_max_rate){
  251. $mzy_max_rate = $data[$i]['rate'];
  252. }
  253. if($data[$i]['rate'] < $mzy_min_rate){
  254. $mzy_min_rate = $data[$i]['rate'];
  255. }
  256. }else{
  257. if($data[$i]['rate'] > $other_max_rate){
  258. $other_max_rate = $data[$i]['rate'];
  259. }
  260. if($data[$i]['rate'] < $other_min_rate){
  261. $other_min_rate = $data[$i]['rate'];
  262. }
  263. }
  264. }
  265. for($i=0;$i<count($data);$i++){
  266. if (strpos($data[$i]['title'], '煤矿') !== false || strpos($data[$i]['title'], '洗选') !== false) {
  267. if($data[$i]['rate'] == $unit_max_rate){
  268. $unit_max_name = $unit_max_name.'、'.$data[$i]['title'];
  269. }
  270. if($data[$i]['rate'] == $unit_min_rate){
  271. $unit_min_name = $unit_max_name.'、'.$data[$i]['title'];
  272. }
  273. }elseif(strpos($data[$i]['title'], '煤制油') !== false || strpos($data[$i]['title'], '烯烃') !== false || strpos($data[$i]['title'], '甲醇') !== false || strpos($data[$i]['title'], '精蜡') !== false){
  274. if($data[$i]['rate'] == $mzy_max_rate){
  275. $mzy_max_name = $mzy_max_name.'、'.$data[$i]['title'];
  276. }
  277. if($data[$i]['rate'] == $mzy_min_rate){
  278. $mzy_min_name = $mzy_max_name.'、'.$data[$i]['title'];
  279. }
  280. }else{
  281. if($data[$i]['rate'] == $other_max_rate){
  282. $other_max_name = $other_max_name.'、'.$data[$i]['title'];
  283. }
  284. if($data[$i]['rate'] == $other_min_rate){
  285. $other_min_name = $other_max_name.'、'.$data[$i]['title'];
  286. }
  287. }
  288. }
  289. }
  290. $unit_max_name = mb_substr($unit_max_name, 1);
  291. $unit_min_name = mb_substr($unit_min_name, 1);
  292. $mzy_max_name = mb_substr($mzy_max_name, 1);
  293. $mzy_min_name = mb_substr($mzy_min_name, 1);
  294. $other_max_name = mb_substr($other_max_name, 1);
  295. $other_min_name = mb_substr($other_min_name, 1);
  296. $result['data'] = '本周公司视频摄像头在线数'.$nm['total_online'].'个,'.'在线率为'.$nm['rate'].'%('.$time
  297. .'统计)。其中:①煤炭生产建设单位在线率排名第一的单位是'.$unit_max_name.',在线率达到'.$unit_max_rate
  298. .'%;排名末位的单位是'.$unit_min_name.',在线率达到'.$unit_min_rate
  299. .'%。②煤制油化工单位在线率排名第一的单位是'.$mzy_max_name.',在线率达到'.$mzy_max_rate.'%;排名末位的单位是'
  300. .$mzy_min_name.',在线率达到'.$mzy_min_rate.'%。③其他单位在线率排名第一的单位是'.$other_max_name
  301. .',在线率达到'.$other_max_rate.'%;排名末位的单位是'.$other_min_name.',在线率达到'.$other_min_rate.'%。';
  302. return self::successResponse($result);
  303. }
  304. //宁煤不在线摄像头列表
  305. public function offlineList(){
  306. $mine_code = Input::get('mine_code', '');
  307. if (!$mine_code) {
  308. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  309. }
  310. $result['status'] = true;
  311. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  312. //宁煤集团
  313. $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
  314. $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
  315. $mine_ningmei = [];//宁煤集团所有区域
  316. foreach($mine_all as $k=>$v){
  317. if(explode('|',$v->degree)[0] == $ningmei[0]->id){
  318. $mine_ningmei[] = $v->id;
  319. }
  320. }
  321. if(count(explode('_',$mine_code)) > 1){
  322. $mine_code = explode('_',$mine_code)[0];
  323. }
  324. $mine_list = DB::table('mine_list')->where('parent_id',0)->where('slug','like','%'.$mine_code.'%')->where('deleted_at',null)->get();
  325. //如果传参是宁煤显示全部
  326. if(isset($mine_list[0]->title) && $mine_list[0]->title == config('mine_hls')[0]){
  327. //宁煤在离线数量
  328. $offline_list = DB::table('camera_list')->select('id','camera_name','cover_picture','camera_status')->whereIn('mine_id',$mine_ningmei)->where('camera_status','!=',1)->where('deleted_at',null)->get();
  329. return self::successResponse($offline_list);
  330. }
  331. //宁煤下各矿在离线数量
  332. $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('slug','like','%'.$mine_code.'%')->where('deleted_at',null)->get();
  333. $total_offline = [];
  334. foreach($mine_list as $k => $v){
  335. $mine_use = [];//宁煤下每个矿所有区域
  336. foreach($mine_all as $key=>$value){
  337. if(count(explode('|',$value->degree)) > 1){
  338. if(explode('|',$value->degree)[0] == $ningmei[0]->id && explode('|',$value->degree)[1] == $v->id){
  339. $mine_use[] = $value->id;
  340. }
  341. }
  342. }
  343. $total_offline = DB::table('camera_list')->select('id','camera_name','cover_picture','camera_status')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('camera_status','!=',1)->where('deleted_at',null)->get();
  344. }
  345. return self::successResponse($total_offline);
  346. }
  347. //宁煤高风险摄像头
  348. public function getRiskNingmei(){
  349. $mine_code = Input::get('mine_code', '');
  350. if (!$mine_code) {
  351. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  352. }
  353. $result['status'] = true;
  354. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  355. //宁煤集团
  356. $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
  357. //宁煤集团下级单位
  358. $mine = DB::table('mine_list')
  359. ->where('parent_id',$ningmei[0]->id)
  360. ->where('slug','like','%'.$mine_code.'%')
  361. ->where('deleted_at',null)
  362. ->get();
  363. //子区域树形列表
  364. $child_list = DB::table('mine_list')->where('parent_id',$mine[0]->id)->where('deleted_at',null)->orderBy('sort','desc')->get();
  365. $risk_id = null;
  366. if(count($child_list)>0){
  367. $risk_id = $this->mineTree($child_list);
  368. }
  369. $mine_list = [];
  370. if($risk_id != null){
  371. $risk = DB::table('mine_list')->where('parent_id',$risk_id)->where('deleted_at',null)->get();
  372. if(count($risk) > 0){
  373. //有子区域
  374. $mine_list = $this->riskTree($risk,[]);
  375. }else{
  376. //没有子区域
  377. $mine_list[] = $risk_id;
  378. }
  379. }
  380. $camera_list = DB::table('camera_list')
  381. ->select('camera_list.*','mine_list.title')
  382. ->leftJoin('mine_list','camera_list.mine_id','=','mine_list.id')
  383. ->where('camera_list.deleted_at',null)
  384. ->whereIn('camera_list.mine_id',$mine_list)
  385. ->orderBy('sort', 'desc')->get();
  386. $result = [];
  387. foreach($camera_list as $k=>$v){
  388. $result[$k]['parent_id'] = $ningmei[0]->id;
  389. $result[$k]['camera_id'] = $v->id;
  390. $result[$k]['mine_name'] = $v->title;
  391. $result[$k]['camera_name'] = $v->camera_name;
  392. $result[$k]['cover_picture'] = $v->cover_picture;
  393. $result[$k]['camera_status'] = $v->camera_status;
  394. $result[$k]['base64'] = $v->base64;
  395. }
  396. return self::successResponse($result);
  397. }
  398. public function mineTree($regions)
  399. {
  400. $arr = null;
  401. foreach ($regions as $key => $value) {
  402. $risk = explode('高风险作业',$value->title);
  403. if (count($risk)>1){
  404. return $value->id;
  405. }
  406. $mine_child = DB::table('mine_list')->where('parent_id', $value->id)->where('deleted_at',null)->get();
  407. if (count($mine_child) > 0) {
  408. $arr = self::mineTree($mine_child, $value->id);
  409. if($arr != null){
  410. return $arr;
  411. }
  412. }
  413. }
  414. return $arr;
  415. }
  416. public function riskTree($regions,$risk_list)
  417. {
  418. foreach ($regions as $key => $value) {
  419. $risk_child = DB::table('mine_list')->where('parent_id', $value->id)->where('deleted_at',null)->get();
  420. if (count($risk_child) > 0) {
  421. $risk_list = array_merge($risk_list,self::riskTree($risk_child,[]));
  422. }else{
  423. $risk_list[] = $value->id;
  424. }
  425. }
  426. return $risk_list;
  427. }
  428. //高风险区域摄像头
  429. public function getCameraByMinecode(){
  430. $mine_code = Input::get('mine_code', '');
  431. if (!$mine_code) {
  432. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  433. }
  434. $result['status'] = true;
  435. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  436. $mine = DB::table('mine_list')->where('slug','like','%'.$mine_code.'%')->where('parent_id',0)->where('deleted_at',null)->first();
  437. if (!$mine) {
  438. $result['status'] = false;
  439. $result['msg'] = '矿区名称不存在';
  440. return $result;
  441. }
  442. $mine_list = DB::table('mine_list')->where('degree', 'like', $mine->id . '|' . '%')->where('title','like','%高风险%')->where('deleted_at',null)->get();
  443. $mine_array = [];
  444. foreach($mine_list as $k=>$v){
  445. $mine_child = DB::table('mine_list')->where('degree', 'like','%' . $v->id . '%')->where('deleted_at',null)->get();
  446. if(count($mine_child)>0){
  447. for($i=0;$i<count($mine_child);$i++){
  448. $mine_array[] = $mine_child[$i]->id;
  449. }
  450. }
  451. }
  452. $query = DB::table('camera_list')
  453. ->select('camera_list.*','mine_list.title')
  454. ->leftJoin('mine_list','camera_list.mine_id','=','mine_list.id')
  455. ->where('camera_list.deleted_at',null)
  456. ->whereIn('camera_list.mine_id',$mine_array)
  457. ->orderBy('sort', 'desc')->get();
  458. if (!$query) {
  459. $result['status'] = false;
  460. $result['msg'] = '矿区下没有摄像头';
  461. return $result;
  462. }
  463. $result = [];
  464. foreach($query as $k=>$v){
  465. $result[$k]['parent_id'] = $mine->id;
  466. $result[$k]['camera_id'] = $v->id;
  467. $result[$k]['mine_name'] = $v->title;
  468. $result[$k]['camera_name'] = $v->camera_name;
  469. $result[$k]['cover_picture'] = $v->cover_picture;
  470. $result[$k]['camera_status'] = $v->camera_status;
  471. }
  472. return self::successResponse($result);
  473. }
  474. /**
  475. * 作者: qiuzijian
  476. * 注释: 获取摄像头列表
  477. * @return \App\Http\Controllers\Api\JsonResponse
  478. */
  479. public function getCamerasList()
  480. {
  481. $parent_id = Input::get('parent_id', '');
  482. $mine_id = Input::get('mine_id', '');
  483. $camera_type = Input::get('camera_type', CameraEnum::CAMERA_TYPE_ALL);
  484. $surface_id = Input::get('surface_id', '');
  485. if (!$parent_id) {
  486. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  487. }
  488. if (!in_array($camera_type, [CameraEnum::CAMERA_TYPE_NORMAL, CameraEnum::CAMERA_TYPE_ALL]) && !$surface_id) {
  489. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  490. }
  491. //判断是否使用海康视频服务器
  492. // $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
  493. // if ($is_hak) {
  494. // $result = CameraServices::getHaiKangCamera($parent_id, $mine_id, $camera_type);
  495. // } else {
  496. $result = CameraServices::getCameraListByMineId($mine_id, $camera_type, $parent_id, $surface_id);
  497. // }
  498. return self::successResponse($result);
  499. }
  500. /**
  501. * 作者: qiuzijian
  502. * 注释: 获取摄像头播放地址
  503. * @return \App\Http\Controllers\Api\JsonResponse
  504. */
  505. public function getCamerasUrl()
  506. {
  507. $parent_id = Input::get('parent_id', '');
  508. $camera_id = Input::get('camera_id', '');
  509. if (!$parent_id || !$camera_id) {
  510. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  511. }
  512. //判断摄像头来源是否为内网服务器
  513. $camera_source = CameraList::where('id', $camera_id)->value('camera_source');
  514. if ($camera_source == CameraEnum::CAMERA_SOURCE_3) {
  515. $result = CameraServices::getIntranetCameraUrl($camera_id);
  516. return self::successResponse($result);
  517. }
  518. //判断是否使用海康视频服务器
  519. $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
  520. //判断是否生成摄像头请求链接
  521. $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
  522. if ($is_hak && !$camera_url) {
  523. //判断是否是mine配置文件的矿区
  524. $mine_res = DB::table('mine_list')->where('id',$parent_id)->get();
  525. //天地伟业
  526. if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine'))){
  527. $result = CameraServices::getRtspTianDi($camera_id,$parent_id);
  528. //宁煤集团
  529. }elseif(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine_hls'))){
  530. $result = CameraServices::getHkHls($camera_id,$parent_id);
  531. }
  532. //大华摄像头
  533. elseif($is_hak == 2){
  534. //同步大华视频服务器摄像头
  535. $tdwy = new TdwyController();
  536. $result = $tdwy->dahuaRtsp($camera_id,$parent_id);
  537. }
  538. //信息技术中心测试ws协议
  539. // elseif($mine_res[0]-> slug == 'XinXiJiShuZhongXin'){
  540. // $result = CameraServices::getHkWs($camera_id,$parent_id);
  541. //
  542. // }
  543. //海康切片逻辑
  544. else{
  545. $result = CameraServices::downloadCameraFiles($parent_id, $camera_id);
  546. }
  547. } else {
  548. //判断硬盘录像机的有没有封面图,有的走easydrawin,没有的走ffmpeg
  549. $cover_picture = CameraList::where('id', $camera_id)->value('cover_picture');
  550. // if(!$cover_picture){
  551. //ffmpeg拉流获取首帧图片
  552. // $result = CameraServices::getCameraUrlByFfmpeg($camera_id);
  553. // }else{
  554. // $result = CameraServices::getCameraUrlByCameraId($camera_id);
  555. // $result = CameraServices::getRtspYingPan($camera_id);
  556. //硬盘录像机切片测试
  557. $result = CameraServices::getRtspQiePian($camera_id);
  558. // }
  559. }
  560. return self::successResponse($result);
  561. }
  562. public function getCamerasLanUrl()
  563. {
  564. $parent_id = Input::get('parent_id', '');
  565. $camera_id = Input::get('camera_id', '');
  566. if (!$parent_id || !$camera_id) {
  567. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  568. }
  569. //判断摄像头来源是否为内网服务器
  570. $camera_source = CameraList::where('id', $camera_id)->value('camera_source');
  571. if ($camera_source == CameraEnum::CAMERA_SOURCE_3) {
  572. $result = CameraServices::getIntranetCameraUrl($camera_id);
  573. return self::successResponse($result);
  574. }
  575. //判断是否使用海康视频服务器
  576. $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
  577. //判断是否生成摄像头请求链接
  578. $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
  579. if ($is_hak && !$camera_url) {
  580. //判断是否是mine配置文件的矿区
  581. $mine_res = DB::table('mine_list')->where('id',$parent_id)->get();
  582. //天地伟业
  583. if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine'))){
  584. $result = CameraServices::getRtspTianDi($camera_id,$parent_id);
  585. //宁煤集团
  586. }elseif(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine_hls'))){
  587. $result = CameraServices::getHkHls($camera_id,$parent_id);
  588. }else{
  589. $result = CameraServices::getLanCameraUrl($parent_id, $camera_id);
  590. }
  591. } else {
  592. //判断硬盘录像机的有没有封面图,有的走easydrawin,没有的走ffmpeg
  593. $cover_picture = CameraList::where('id', $camera_id)->value('cover_picture');
  594. // if(!$cover_picture){
  595. //ffmpeg拉流获取首帧图片
  596. // $result = CameraServices::getCameraUrlByFfmpeg($camera_id);
  597. // }else{
  598. $result = CameraServices::getCameraUrlByCameraId($camera_id);
  599. // }
  600. }
  601. return self::successResponse($result);
  602. }
  603. //获取海康rtsp流
  604. public function getHikRtsp(){
  605. $parent_id = Input::get('parent_id', '');
  606. $camera_id = Input::get('camera_id', '');
  607. if (!$parent_id || !$camera_id) {
  608. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  609. }
  610. //判断是否使用海康视频服务器
  611. $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
  612. //判断是否生成摄像头请求链接
  613. $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
  614. if ($is_hak == 1 && !$camera_url) {
  615. $result = CameraServices::getHkRtsp($camera_id,$parent_id);
  616. return self::successResponse($result);
  617. }else{
  618. return self::errorResponse(ApiEnum::HK_REQUEST_FAIL);
  619. }
  620. }
  621. //获取海康rtmp流
  622. public function getHikRtmp(){
  623. $parent_id = Input::get('parent_id', '');
  624. $camera_id = Input::get('camera_id', '');
  625. if (!$parent_id || !$camera_id) {
  626. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  627. }
  628. //判断是否使用海康视频服务器
  629. $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
  630. //判断是否生成摄像头请求链接
  631. $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
  632. if ($is_hak == 1 && !$camera_url) {
  633. $result = CameraServices::getHkRtmp($camera_id,$parent_id);
  634. return self::successResponse($result);
  635. }else{
  636. return self::errorResponse(ApiEnum::HK_REQUEST_FAIL);
  637. }
  638. }
  639. //海康摄像头easy_drawin方式获取url
  640. public function getCamerasRtsp()
  641. {
  642. $parent_id = Input::get('parent_id', '');
  643. $camera_id = Input::get('camera_id', '');
  644. if (!$parent_id || !$camera_id) {
  645. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  646. }
  647. //判断摄像头来源是否为内网服务器
  648. $camera_source = CameraList::where('id', $camera_id)->value('camera_source');
  649. if ($camera_source == CameraEnum::CAMERA_SOURCE_3) {
  650. $result = CameraServices::getIntranetCameraUrl($camera_id);
  651. return self::successResponse($result);
  652. }
  653. //判断是否使用海康视频服务器
  654. $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
  655. //判断是否生成摄像头请求链接
  656. $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
  657. if ($is_hak && !$camera_url) {
  658. //判断是否是mine配置文件的矿区
  659. $mine_res = DB::table('mine_list')->where('id',$parent_id)->get();
  660. if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine'))){
  661. //天地伟业使用easy_drawin获取rtsp
  662. $result = CameraServices::getRtspTianDi($camera_id,$parent_id);
  663. }else{
  664. //海康使用easy_drawin获取rtsp
  665. $result = CameraServices::getRtspHaiKang($camera_id, $parent_id);
  666. }
  667. } else {
  668. //硬盘录像机使用easy_drawin获取rtsp
  669. $result = CameraServices::getRtspYingPan($camera_id);
  670. }
  671. return self::successResponse($result);
  672. }
  673. /**
  674. * 作者: qiuzijian
  675. * 注释: 停止摄像头推流
  676. * @return \App\Http\Controllers\Api\JsonResponse
  677. */
  678. public function stopCamerasStream()
  679. {
  680. $camera_id = Input::get('camera_id', '');
  681. $result = CameraServices::stopCameraStream();
  682. return self::successResponse($result);
  683. }
  684. //回放列表
  685. public function getPlaybackList(){
  686. $camera_id = Input::get('camera_id', '');
  687. $result['status'] = true;
  688. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  689. if (!$camera_id) {
  690. $result['status'] = false;
  691. $result['msg'] = ApiEnum::STATUS_CODE_EMPTY;
  692. return $result;
  693. }
  694. $query = CameraList::where('id', $camera_id)->first();
  695. if (!$query) {
  696. $result['status'] = false;
  697. $result['msg'] = ApiEnum::NO_CAMERA_URL;
  698. return $result;
  699. }
  700. if($query->playback == 0){
  701. $result['status'] = false;
  702. $result['msg'] = ApiEnum::NO_SUPORT_PLAYBACK;
  703. return $result;
  704. }
  705. $playback = DB::table('playback')->where('camera_id',$query->id)->where('deleted_at',null)->get();
  706. if(count($playback)>0){
  707. for($i=0;$i<count($playback);$i++){
  708. $result['data'][$i]['title'] = $playback[$i]->title;
  709. $result['data'][$i]['start_time'] = $playback[$i]->start_time;
  710. $result['data'][$i]['end_time'] = $playback[$i]->end_time;
  711. $result['data'][$i]['camera_id'] = $playback[$i]->camera_id;
  712. }
  713. }else{
  714. $result['data'] = null;
  715. }
  716. return $result;
  717. }
  718. //回放URL
  719. public function getPlaybackUrl(){
  720. $time['start_time'] = explode(' ',Input::get('start_time', ''))[1];
  721. $time['end_time'] = explode(' ',Input::get('end_time', ''))[1];
  722. $camera_id = Input::get('camera_id', '');
  723. $start_time = Input::get('start_time', '');
  724. $end_time = Input::get('end_time', '');
  725. $result['status'] = true;
  726. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  727. if (!$camera_id || !$start_time || !$end_time) {
  728. $result['status'] = false;
  729. $result['msg'] = ApiEnum::STATUS_CODE_EMPTY;
  730. return $result;
  731. }
  732. $query = CameraList::where('id', $camera_id)->first();
  733. if (!$query) {
  734. $result['status'] = false;
  735. $result['msg'] = ApiEnum::NO_CAMERA_URL;
  736. return $result;
  737. }
  738. if($query->playback == 0){
  739. $result['status'] = false;
  740. $result['msg'] = ApiEnum::NO_SUPORT_PLAYBACK;
  741. return $result;
  742. }
  743. $degree = MineList::where('id', $query->mine_id)->value('degree');
  744. $degree = explode('|', $degree)[0];
  745. $mine_res = DB::table('mine_list')->where('id',$degree)->get();
  746. //判断摄像头是否是洗选中心的时间+34分钟
  747. if($mine_res[0]->slug == 'XiXuanZhongXin'){
  748. $start_time = date('Y-m-d H:i:s',strtotime($start_time.'+34 minutes'));
  749. $end_time = date('Y-m-d H:i:s',strtotime($end_time.'+34 minutes'));
  750. }
  751. $str = '.000+';
  752. $start_time = date('c', strtotime($start_time));//2022-07-14T08:00:00.000+08:00
  753. $start_time = explode('+',$start_time);
  754. $start_time = $start_time[0].$str.$start_time[1];
  755. $end_time = date('c', strtotime($end_time));
  756. $end_time = explode('+',$end_time);
  757. $end_time = $end_time[0].$str.$end_time[1];
  758. //判断是否在配置文件里,在的不用走ffmpeg
  759. if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('playback'))){
  760. $result = CameraServices::getPlaybackRtsp($camera_id,$start_time,$end_time);
  761. return self::successResponse($result);
  762. }else{
  763. $result = CameraServices::getPlaybackRtmp($camera_id,$start_time,$end_time,$time);
  764. return self::successResponse($result);
  765. }
  766. }
  767. //easydrawin回放URL
  768. public function getPlaybackUrlByEasy(){
  769. $time['start_time'] = explode(' ',Input::get('start_time', ''))[1];
  770. $time['end_time'] = explode(' ',Input::get('end_time', ''))[1];
  771. $camera_id = Input::get('camera_id', '');
  772. $start_time = Input::get('start_time', '');
  773. $end_time = Input::get('end_time', '');
  774. $result['status'] = true;
  775. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  776. if (!$camera_id || !$start_time || !$end_time) {
  777. $result['status'] = false;
  778. $result['msg'] = ApiEnum::STATUS_CODE_EMPTY;
  779. return $result;
  780. }
  781. $query = CameraList::where('id', $camera_id)->first();
  782. if (!$query) {
  783. $result['status'] = false;
  784. $result['msg'] = ApiEnum::NO_CAMERA_URL;
  785. return $result;
  786. }
  787. if($query->playback == 0){
  788. $result['status'] = false;
  789. $result['msg'] = ApiEnum::NO_SUPORT_PLAYBACK;
  790. return $result;
  791. }
  792. $degree = MineList::where('id', $query->mine_id)->value('degree');
  793. $degree = explode('|', $degree)[0];
  794. $mine_res = DB::table('mine_list')->where('id',$degree)->get();
  795. //判断摄像头是否是洗选中心的时间+34分钟
  796. if($mine_res[0]->slug == 'XiXuanZhongXin'){
  797. $start_time = date('Y-m-d H:i:s',strtotime($start_time.'+34 minutes'));
  798. $end_time = date('Y-m-d H:i:s',strtotime($end_time.'+34 minutes'));
  799. }
  800. $str = '.000+';
  801. $start_time = date('c', strtotime($start_time));//2022-07-14T08:00:00.000+08:00
  802. $start_time = explode('+',$start_time);
  803. $start_time = $start_time[0].$str.$start_time[1];
  804. $end_time = date('c', strtotime($end_time));
  805. $end_time = explode('+',$end_time);
  806. $end_time = $end_time[0].$str.$end_time[1];
  807. //判断是否在配置文件里,在的不用走ffmpeg
  808. if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('playback'))){
  809. $result = CameraServices::getPlaybackRtsp($camera_id,$start_time,$end_time);
  810. return self::successResponse($result);
  811. }else{
  812. $result = CameraServices::getPlaybackByEasy($camera_id,$start_time,$end_time,$time);
  813. return self::successResponse($result);
  814. }
  815. }
  816. /**
  817. * 作者: qiuzijian
  818. * 注释: 获取编码设备信息
  819. * @return \App\Http\Controllers\Api\JsonResponse
  820. */
  821. public function getTranscodeInfo()
  822. {
  823. $parent_id = Input::get('parent_id', '');
  824. if (!$parent_id) {
  825. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  826. }
  827. $result = CameraServices::getHaiKangTransCode($parent_id);
  828. return self::successResponse($result);
  829. }
  830. /**
  831. * 作者: qiuzijian
  832. * 注释: 获取大南湖摄像头列表
  833. * @return \App\Http\Controllers\Api\JsonResponse
  834. */
  835. public function getSouthLakeCamera()
  836. {
  837. $result = CameraServices::getLeChangeCamera();
  838. return self::successResponse($result);
  839. }
  840. public function pictureBase64(){
  841. $base64 = Input::get('base64', '');
  842. $camera_id = Input::get('camera_id', '');
  843. if (!$base64 || !$camera_id) {
  844. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  845. }
  846. $data['base64'] = $base64;
  847. DB::table('camera_list')->where('id',$camera_id)->update($data);
  848. return self::successResponse();
  849. }
  850. public function test(){
  851. // header("Access-Control-Allow-Origin: *");
  852. $data = DB::table('goods')->get();
  853. return $data;
  854. }
  855. public function testadd(){
  856. // header("Access-Control-Allow-Origin: *");
  857. $res['good_name'] = Input::get('good_name', '');
  858. $res['good_url'] = 'images/1.jpg';
  859. $res['good_count'] = Input::get('good_count', '');
  860. $res['good_price'] = Input::get('good_price', '');
  861. $res['good_state'] = Input::get('good_state', '');
  862. DB::table('goods')->insert($res);
  863. return true;
  864. }
  865. public function testdel(){
  866. // header("Access-Control-Allow-Origin: *");
  867. DB::table('goods')->where('id',Input::get('id',''))->delete();
  868. return true;
  869. }
  870. public function testupdate(){
  871. // header("Access-Control-Allow-Origin: *");
  872. $res['good_name'] = Input::get('good_name', '');
  873. $res['good_url'] = 'images/1.jpg';
  874. $res['good_count'] = Input::get('good_count', '');
  875. $res['good_price'] = Input::get('good_price', '');
  876. $res['good_state'] = Input::get('good_state', '');
  877. DB::table('goods')->where('id',Input::get('id',''))->update($res);
  878. return true;
  879. }
  880. //值班信息
  881. public function dutyInformation(){
  882. $today = date('Y-m-d');
  883. $tomorrow = date("Y-m-d",strtotime("+1 day"));
  884. $result['today_zzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$today."' and type = 'zzb'");
  885. $result['today_fzzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$today."' and type = 'fz'");
  886. $result['tomorrow_zzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$tomorrow."' and type = 'zzb'");
  887. $result['tomorrow_fzzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$tomorrow."' and type = 'fz'");
  888. return self::successResponse($result);
  889. }
  890. //分类列表
  891. public function typeList(){
  892. $result = $result = DB::connection('etl_zaoquan')->select("select type from news_column_list group by type");
  893. if(count($result) > 0){
  894. for($i=0;$i<count($result);$i++){
  895. if($result[$i]->type=="mkxw"){
  896. unset($result[$i]);
  897. $newObject = ['type' => 'mkxw','name'=>'煤矿新闻'];
  898. array_unshift($result, $newObject);
  899. }
  900. if($result[$i]->type == 'aqsc'){
  901. $result[$i]->name = '安全生产';
  902. }
  903. if($result[$i]->type == 'mkxw'){
  904. $result[$i]->name = '煤矿新闻';
  905. }
  906. if($result[$i]->type == 'zwbg'){
  907. $result[$i]->name = '政务办公';
  908. }
  909. if($result[$i]->type == 'djgz'){
  910. $result[$i]->name = '党建工作';
  911. }
  912. if($result[$i]->type == 'qygl'){
  913. $result[$i]->name = '企业管理';
  914. }
  915. if($result[$i]->type == 'jdgl'){
  916. $result[$i]->name = '机电管理';
  917. }
  918. if($result[$i]->type == 'scjsgl'){
  919. $result[$i]->name = '生产技术管理';
  920. }
  921. if($result[$i]->type == 'jjjc'){
  922. $result[$i]->name = '纪检监察';
  923. }
  924. if($result[$i]->type == 'zhzl'){
  925. $result[$i]->name = '综合治理';
  926. }
  927. if($result[$i]->type == 'jypx'){
  928. $result[$i]->name = '教育培训';
  929. }
  930. if($result[$i]->type == 'kwgk'){
  931. $result[$i]->name = '矿务公开';
  932. }
  933. }
  934. }
  935. return self::successResponse($result);
  936. }
  937. //文章列表
  938. public function articleList(Request $request){
  939. $params = $request->all();
  940. if (!isset($params['page_size'])) {
  941. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  942. }
  943. if (!isset($params['page_num'])) {
  944. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  945. }
  946. if (!isset($params['type'])) {
  947. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  948. }
  949. $offset = $params['page_size'] * ($params['page_num'] - 1);
  950. $result = DB::connection('etl_zaoquan')->select("select * from news_column_list where type = '".$params['type']."' order by create_time desc limit ".$params['page_size']." offset ".$offset);
  951. $pattern = '/<img(.*?)src=["\'](.*?)["\'](.*?)>/i';//图片
  952. $pattern2 = '/href="([^"]+)"/';//文件
  953. if(count($result) > 0){
  954. for($i=0;$i<count($result);$i++){
  955. //替换title_image
  956. $old_title_image = $result[$i]->title_image;
  957. $old_title_image_array = explode('/',$old_title_image);
  958. $old_img_path = $old_title_image_array[count($old_title_image_array)-1];
  959. $new_img_path_list = DB::connection('etl_zaoquan')->select("select * from news_img_list where img_name ='".$old_img_path."'");
  960. if(count($new_img_path_list) > 0){
  961. $result[$i]->main_img = $new_img_path_list[0]->new_name;
  962. }
  963. unset($result[$i]->title_image);
  964. $result[$i]->created_at = $result[$i]->create_time;
  965. unset($result[$i]->create_time);
  966. //替换text的图片
  967. preg_match_all($pattern, $result[$i]->text, $matches);
  968. foreach ($matches[2] as $index => $oldSrc) {
  969. $news_img_list = DB::connection('etl_zaoquan')->select("select * from news_img_list where img_name ='".basename($oldSrc)."'");
  970. if(count($news_img_list) > 0){
  971. $newSrc = $news_img_list[0]->new_name;
  972. $result[$i]->text = str_replace($oldSrc, $newSrc, $result[$i]->text);
  973. }
  974. }
  975. //替换text的文件
  976. preg_match_all($pattern2, $result[$i]->text, $matches2);
  977. foreach ($matches2[1] as $index => $oldSrc) {
  978. $news_file_list = DB::connection('etl_zaoquan')->select("select * from news_img_list where img_name ='".basename($oldSrc)."'");
  979. if(count($news_file_list) > 0){
  980. $newSrc = $news_file_list[0]->new_name;
  981. $result[$i]->text = str_replace($oldSrc, $newSrc, $result[$i]->text);
  982. }
  983. }
  984. }
  985. }
  986. return self::successResponse($result);
  987. }
  988. //文章图片上传至阿里云
  989. public function ossUrl(Request $request){
  990. $params = $request->all();
  991. if (!isset($params['url'])) {
  992. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  993. }
  994. $result = $this->downloadFile($params['url']);
  995. return self::successResponse($result);
  996. }
  997. //下载文件
  998. public function downloadFile($file_path)
  999. {
  1000. $rename = mt_rand(1111111,9999999);
  1001. if (!$file_path) {
  1002. return false;
  1003. }
  1004. set_time_limit(0);
  1005. $ch = curl_init($file_path);
  1006. curl_setopt($ch, CURLOPT_HEADER, 0);
  1007. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1008. curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
  1009. $rawdata = curl_exec ($ch);
  1010. curl_close ($ch);
  1011. $houzhui = explode('.',$file_path);
  1012. $houzhui = '.'.$houzhui[count($houzhui)-1];
  1013. // 使用中文文件名需要转码
  1014. $fp = fopen(public_path() . '/filedownload/' . $rename.$houzhui, 'w');
  1015. fwrite($fp, $rawdata);
  1016. fclose($fp);
  1017. $file_name = $rename;
  1018. //上传文件
  1019. $file_oss_path = $this->uploadFile($file_name,$houzhui);
  1020. return $file_oss_path;
  1021. }
  1022. //上传文件
  1023. public function uploadFile($file_name,$houzhui)
  1024. {
  1025. try{
  1026. $oss = new OssClient(
  1027. Config::get('filesystems.disks.oss_view.access_key'),
  1028. Config::get('filesystems.disks.oss_view.secret_key'),
  1029. Config::get('filesystems.disks.oss_view.endpoint')
  1030. );
  1031. $file_path = public_path() . '/filedownload/' . $file_name.$houzhui;
  1032. $res = $oss->uploadFile(Config::get('filesystems.disks.oss_view.bucket'), $file_name.$houzhui, $file_path);
  1033. } catch(\OssException $e) {
  1034. printf(__FUNCTION__ . ": FAILED\n");
  1035. printf($e->getMessage() . "\n");
  1036. return;
  1037. }
  1038. if (isset($res['info']['url']) && $res['info']['url']) {
  1039. unlink($file_path);
  1040. return urldecode($res['info']['url']);
  1041. } else {
  1042. return false;
  1043. }
  1044. }
  1045. //摄像头访问记录入库
  1046. public function cameraRecordInsert(Request $request){
  1047. $params = $request->all();
  1048. // $opcDB = DB::connection('anning');
  1049. // $dbResult = $opcDB->select('select * from uf_dwj_spjkymfw where ymid = 6224');
  1050. if(isset($params['staff_num']) && isset($params['name']) && isset($params['department']) && isset($params['post']) && isset($params['camera_id']) && isset($params['start_time'])){
  1051. $camera = DB::table('camera_list')->where('id',$params['camera_id'])->get();
  1052. $mine = DB::table('mine_list')->where('id',$camera[0]->mine_id)->get();
  1053. $degree = explode('|',$mine[0]->degree);
  1054. $unit = DB::table('mine_list')->where('id',$degree[0])->get();
  1055. $data['staff_num'] = $params['staff_num'];
  1056. $data['name'] = $params['name'];
  1057. $data['department'] = $params['department'];
  1058. $data['post'] = $params['post'];
  1059. $data['mine_id'] = $camera[0]->mine_id;
  1060. $data['camera_id'] = $params['camera_id'];
  1061. $data['camera_name'] = $camera[0]->camera_name;
  1062. $data['unit_name'] = $unit[0]->title;
  1063. if(isset($params['base64']) && $params['base64'] != null && $params['base64'] != ''){
  1064. $data['base64'] = $params['base64'];
  1065. }
  1066. $data['start_time'] = date('Y-m-d').' '.$params['start_time'];
  1067. // $data['start_time'] = date('Y-m-d').' '.$params['end_time'];
  1068. $data['created_at'] = date('Y-m-d H:i:s');
  1069. $data['updated_at'] = date('Y-m-d H:i:s');
  1070. DB::table('camera_record')->insert($data);
  1071. }
  1072. }
  1073. //摄像头访问记录列表
  1074. public function cameraRecordList(Request $request){
  1075. $params = $request->all();
  1076. if (!isset($params['camera_id'])) {
  1077. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1078. }
  1079. $camera_record = DB::table('camera_record')->where('camera_id',$params['camera_id'])->where('deleted_at',null)->orderBy('created_at','desc')->limit(20)->get();
  1080. return self::successResponse($camera_record);
  1081. }
  1082. //摄像头下拉列表
  1083. public function cameraSelect(Request $request){
  1084. $result = '<select style="width:99%;" class="form-control" name="camera"><option value="0">-选择摄像头-</option>';
  1085. $mine_list = DB::table('mine_list')->where('parent_id',6356)->where('deleted_at',null)->get();
  1086. if(count($mine_list) > 0){
  1087. for($i=0;$i<count($mine_list);$i++){
  1088. $camera_list = DB::table('camera_list')->where('mine_id',$mine_list[$i]->id)->where('is_show',1)->where('deleted_at',null)->get();
  1089. if(count($camera_list) > 0){
  1090. $result = $result . '<optgroup label="' . $mine_list[$i]->title . '">';
  1091. for($j=0;$j<count($camera_list);$j++){
  1092. $result = $result . '<option value="'.$camera_list[$j]->id.'|'.$mine_list[$i]->id.'|'.$camera_list[$j]->camera_name.'|'.$camera_list[$j]->camera_type.'">'.$camera_list[$j]->camera_name.'('.CameraEnum::CAMERA_TYPE_EXCHANGE[$camera_list[$j]->camera_type].')</option>';
  1093. }
  1094. $result = $result . '</optgroup>';
  1095. }
  1096. }
  1097. }
  1098. $result = $result . '</select>';
  1099. return json_encode($result);
  1100. }
  1101. //摄像头信息
  1102. public function cameraInfo(Request $request){
  1103. $params = $request->all();
  1104. $camera = DB::table('camera_list')->where('id',$params['camera_id'])->get();
  1105. $result['id'] = $camera[0]->id;
  1106. $result['camera_name'] = $camera[0]->camera_name;
  1107. $result['camera_url'] = $camera[0]->camera_url;
  1108. $result['camera_type'] = $camera[0]->camera_type;
  1109. $result['cover_picture'] = $camera[0]->cover_picture;
  1110. $result['parent_id'] = $camera[0]->mine_id;
  1111. return $result;
  1112. }
  1113. //使用说明
  1114. public function readme(Request $request){
  1115. $params = $request->all();
  1116. $result['coal_washery'] = DB::connection('task_xixuan')->table('xx_coal_washery')->orderBy('id')->get();
  1117. $mine_list = DB::table('mine_list')->where('parent_id',6356)->where('deleted_at',null)->get();
  1118. $result['camera_list'] = [];
  1119. if(count($mine_list) > 0){
  1120. for($i=0;$i<count($mine_list);$i++){
  1121. $camera_list = DB::table('camera_list')->where('mine_id',$mine_list[$i]->id)->where('is_show',1)->where('deleted_at',null)->get();
  1122. if(count($camera_list) > 0){
  1123. $result['camera_list'][$i]['area'] = $mine_list[$i]->title;
  1124. for($j=0;$j<count($camera_list);$j++){
  1125. $result['camera_list'][$i]['camera_list'][$j] = $camera_list[$j]->id.':'.$camera_list[$j]->camera_name;
  1126. }
  1127. }
  1128. }
  1129. }
  1130. return $result;
  1131. }
  1132. //主屏幕
  1133. public function mainHome(Request $request){
  1134. $gao = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', today())->where('risk_level',0)->count();
  1135. $zhong = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', today())->where('risk_level',1)->count();
  1136. $di = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', today())->where('risk_level',2)->count();
  1137. $result = [
  1138. [
  1139. 'number' => $gao,
  1140. 'unit' => '项',
  1141. 'title' => '高风险作业',
  1142. 'color' => '#DA0000'
  1143. ],
  1144. [
  1145. 'number' => $zhong,
  1146. 'unit' => '项',
  1147. 'title' => '中风险作业',
  1148. 'color' => '#FFBA00'
  1149. ],
  1150. [
  1151. 'number' => $di,
  1152. 'unit' => '项',
  1153. 'title' => '低风险作业',
  1154. 'color' => '#2BB200'
  1155. ]
  1156. ];
  1157. return self::successResponse($result);
  1158. }
  1159. //风险作业占比
  1160. public function riskWorkPercent(Request $request){
  1161. $gao = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', today())->where('risk_level',0)->count();
  1162. $zhong = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', today())->where('risk_level',1)->count();
  1163. $di = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', today())->where('risk_level',2)->count();
  1164. $result = [
  1165. [
  1166. 'value' => $gao,
  1167. 'name' => '高风险',
  1168. ],
  1169. [
  1170. 'value' => $zhong,
  1171. 'name' => '中风险',
  1172. ],
  1173. [
  1174. 'value' => $di,
  1175. 'name' => '低风险',
  1176. ]
  1177. ];
  1178. return self::successResponse($result);
  1179. }
  1180. //片区占比
  1181. public function areaPercent(Request $request){
  1182. $area = DB::connection('task_xixuan')->table('xx_area')->get();
  1183. if(count($area) > 0){
  1184. for($i=0;$i<count($area);$i++){
  1185. $coal_washery_id_list = DB::connection('task_xixuan')->table('xx_coal_washery')->where('area_id',$area[$i]->id)->pluck('id');
  1186. $result[$i]['value'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('optdt', today())->count();
  1187. $result[$i]['name'] = $area[$i]->name;
  1188. }
  1189. }
  1190. return self::successResponse($result);
  1191. }
  1192. //地图数据
  1193. public function mapData(Request $request){
  1194. $coal_washery = DB::connection('task_xixuan')->table('xx_coal_washery')->get();
  1195. $coal_list = [
  1196. '灵新洗煤厂'=>'linxing',
  1197. '红柳洗煤厂'=>'hongliu',
  1198. '枣泉洗煤厂'=>'zaoquan',
  1199. '大武口洗煤厂'=>'dawukou',
  1200. '金凤洗煤厂'=>'jinfeng',
  1201. '检修车间'=>'jianxiuchejian',
  1202. '太西洗煤厂'=>'taixi',
  1203. '清水营洗煤厂'=>'qingshuiying',
  1204. '梅花井洗煤厂'=>'meihuajing',
  1205. '石槽村洗煤厂'=>'shicaocun',
  1206. '双马洗煤厂'=>'shuangma',
  1207. '羊场湾洗煤厂'=>'yangchangwan',
  1208. '羊场湾二分区洗煤厂'=>'yangchangwanerfenqu'
  1209. ];
  1210. if(count($coal_washery) > 0){
  1211. for($i=0;$i<count($coal_washery);$i++){
  1212. if(array_key_exists($coal_washery[$i]->name, $coal_list)) {
  1213. $slog = $coal_list[$coal_washery[$i]->name];
  1214. $result[$slog]['title'] = $coal_washery[$i]->name;
  1215. $result[$slog]['data'] = [
  1216. [
  1217. 'name' => '高风险作业',
  1218. 'value'=> DB::connection('task_xixuan')->table('xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->id)->where('risk_level',0)->whereDate('optdt', today())->count()
  1219. ],
  1220. [
  1221. 'name' => '中风险作业',
  1222. 'value'=> DB::connection('task_xixuan')->table('xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->id)->where('risk_level',1)->whereDate('optdt', today())->count()
  1223. ],
  1224. [
  1225. 'name' => '低风险作业',
  1226. 'value'=> DB::connection('task_xixuan')->table('xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->id)->where('risk_level',2)->whereDate('optdt', today())->count()
  1227. ]
  1228. ];
  1229. }
  1230. }
  1231. }
  1232. return self::successResponse($result);
  1233. }
  1234. //时间段作业数
  1235. public function timeWorkCount(Request $request){
  1236. $params = $request->all();
  1237. if(isset($params['start_date']) && isset($params['end_date'])){
  1238. $start_date = $params['start_date'];
  1239. $end_date = $params['end_date'];
  1240. }else{
  1241. $start_date = date('Y-m-d', strtotime(date('Y-m-d') . ' -6 day'));
  1242. $end_date = date('Y-m-d');
  1243. }
  1244. $current_date = $start_date;
  1245. $i = 0;
  1246. $result = [];
  1247. $result['xAxis']['type'] = 'category';
  1248. $result['xAxis']['data'] = [];
  1249. $result['series'] = [
  1250. [
  1251. 'name' => '高风险作业',
  1252. 'type' => 'bar',
  1253. 'stack'=> 'bar_1',
  1254. 'data' => [],
  1255. 'itemStyle' => [
  1256. 'color' => '#DA0000',
  1257. 'borderRadius' => [10,10,10,10]
  1258. ]
  1259. ],
  1260. [
  1261. 'name' => '中风险作业',
  1262. 'type' => 'bar',
  1263. 'stack'=> 'bar_2',
  1264. 'data' => [],
  1265. 'itemStyle' => [
  1266. 'color' => '#FFBA00',
  1267. 'borderRadius' => [10,10,10,10]
  1268. ]
  1269. ],
  1270. [
  1271. 'name' => '低风险作业',
  1272. 'type' => 'bar',
  1273. 'stack'=> 'bar_3',
  1274. 'data' => [],
  1275. 'itemStyle' => [
  1276. 'color' => '#2BB200',
  1277. 'borderRadius' => [10,10,10,10]
  1278. ]
  1279. ]
  1280. ];
  1281. while ($current_date <= $end_date) {
  1282. array_push($result['xAxis']['data'],$current_date);
  1283. array_push($result['series'][0]['data'],DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $current_date)->where('risk_level',0)->count());
  1284. array_push($result['series'][1]['data'],DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $current_date)->where('risk_level',1)->count());
  1285. array_push($result['series'][2]['data'],DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $current_date)->where('risk_level',2)->count());
  1286. $current_date = date('Y-m-d', strtotime($current_date . ' +1 day'));
  1287. $i++;
  1288. }
  1289. return self::successResponse($result);
  1290. }
  1291. //时间段片区统计
  1292. public function timeAreaTotal(Request $request){
  1293. $params = $request->all();
  1294. if (isset($params['area_id'])) {
  1295. $area_id = $params['area_id'];
  1296. }else{
  1297. $area_id = 1;
  1298. }
  1299. if(isset($params['start_date']) && isset($params['end_date'])){
  1300. $start_date = $params['start_date'];
  1301. $end_date = $params['end_date'];
  1302. }else{
  1303. $start_date = date('Y-m-d', strtotime(date('Y-m-d') . ' -6 day'));
  1304. $end_date = date('Y-m-d');
  1305. }
  1306. $coal_washery_id_list = DB::connection('task_xixuan')->table('xx_coal_washery')->where('area_id',$area_id)->pluck('id');
  1307. $result = [];
  1308. $current_date = $start_date;
  1309. $i = 0;
  1310. //当日片区数
  1311. $result['data'] = [
  1312. [
  1313. 'number' => DB::connection('task_xixuan')->table('xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('optdt', date('Y-m-d'))->where('risk_level',0)->count(),
  1314. 'unit' => '项',
  1315. 'title' => '高风险作业',
  1316. 'color' => '#DA0000'
  1317. ],
  1318. [
  1319. 'number' => DB::connection('task_xixuan')->table('xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('optdt', date('Y-m-d'))->where('risk_level',1)->count(),
  1320. 'unit' => '项',
  1321. 'title' => '中风险作业',
  1322. 'color' => '#FFBA00'
  1323. ],
  1324. [
  1325. 'number' => DB::connection('task_xixuan')->table('xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('optdt', date('Y-m-d'))->where('risk_level',2)->count(),
  1326. 'unit' => '项',
  1327. 'title' => '低风险作业',
  1328. 'color' => '#2BB200'
  1329. ]
  1330. ];
  1331. $result['xAxis']['type'] = 'category';
  1332. $result['xAxis']['data'] = [];
  1333. $result['series'] = [
  1334. [
  1335. 'name' => '高风险作业',
  1336. 'type' => 'line',
  1337. 'data' => [],
  1338. 'itemStyle' => [
  1339. 'color' => '#DA0000',
  1340. 'borderRadius' => [10,10,10,10]
  1341. ]
  1342. ],
  1343. [
  1344. 'name' => '中风险作业',
  1345. 'type' => 'line',
  1346. 'data' => [],
  1347. 'itemStyle' => [
  1348. 'color' => '#FFBA00',
  1349. 'borderRadius' => [10,10,10,10]
  1350. ]
  1351. ],
  1352. [
  1353. 'name' => '低风险作业',
  1354. 'type' => 'line',
  1355. 'data' => [],
  1356. 'itemStyle' => [
  1357. 'color' => '#2BB200',
  1358. 'borderRadius' => [10,10,10,10]
  1359. ]
  1360. ]
  1361. ];
  1362. while ($current_date <= $end_date) {
  1363. array_push($result['xAxis']['data'],$current_date);
  1364. array_push($result['series'][0]['data'],DB::connection('task_xixuan')->table('xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('optdt', $current_date)->where('risk_level',0)->count());
  1365. array_push($result['series'][1]['data'],DB::connection('task_xixuan')->table('xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('optdt', $current_date)->where('risk_level',1)->count());
  1366. array_push($result['series'][2]['data'],DB::connection('task_xixuan')->table('xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('optdt', $current_date)->where('risk_level',2)->count());
  1367. $current_date = date('Y-m-d', strtotime($current_date . ' +1 day'));
  1368. $i++;
  1369. }
  1370. return self::successResponse($result);
  1371. }
  1372. //洗煤厂统计
  1373. public function coalWasheryTotal(Request $request){
  1374. $coal_washery = DB::connection('task_xixuan')->table('xx_coal_washery')->get();
  1375. if(count($coal_washery) > 0){
  1376. for($i=0;$i<count($coal_washery);$i++){
  1377. $result[$i]['unit_name'] = $coal_washery[$i]->name;
  1378. $result[$i]['data'] = [
  1379. [
  1380. 'label' => '高',
  1381. 'value' => DB::connection('task_xixuan')->table('xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->id)->where('risk_level',0)->whereDate('optdt', today())->count(),
  1382. 'color' => '#DA0000'
  1383. ],
  1384. [
  1385. 'label' => '中',
  1386. 'value' => DB::connection('task_xixuan')->table('xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->id)->where('risk_level',1)->whereDate('optdt', today())->count(),
  1387. 'color' => '#FFBA00'
  1388. ],
  1389. [
  1390. 'label' => '低',
  1391. 'value' => DB::connection('task_xixuan')->table('xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->id)->where('risk_level',2)->whereDate('optdt', today())->count(),
  1392. 'color' => '#2BB200'
  1393. ],
  1394. ];
  1395. }
  1396. }
  1397. return self::successResponse($result);
  1398. }
  1399. //风险作业列表
  1400. public function riskWorkList(Request $request){
  1401. $params = $request->all();
  1402. if(isset($params['type'])){
  1403. $type = $params['type'];
  1404. }else{
  1405. $type = 0;
  1406. }
  1407. $coal_washery_list = DB::connection('task_xixuan')->table('xx_coal_washery')->get();
  1408. if(count($coal_washery_list) > 0){
  1409. for($i=0;$i<count($coal_washery_list);$i++){
  1410. $result['unit_list'][$i]['text'] = $coal_washery_list[$i]->name;
  1411. $result['unit_list'][$i]['value'] = $coal_washery_list[$i]->name;
  1412. }
  1413. }
  1414. $risk = DB::connection('task_xixuan')->table('xx_risk_assignment');
  1415. $risk = $risk->select('xx_risk_assignment.*','xx_coal_washery.name as coal_washery');
  1416. $risk = $risk->leftJoin('xx_coal_washery','xx_coal_washery.id','=','xx_risk_assignment.coal_washery_id');
  1417. $risk = $risk->whereDate('xx_risk_assignment.optdt', today());
  1418. if(isset($params['id'])){
  1419. $risk = $risk->where('xx_coal_washery.id',$params['id']);
  1420. }
  1421. $risk = $risk->where('risk_level',$type)->get();
  1422. $result['data'] = [];
  1423. if(count($risk) > 0){
  1424. for($i=0;$i<count($risk);$i++){
  1425. $result['data'][$i]['id'] = $risk[$i]->id;
  1426. $result['data'][$i]['unit_name'] = $risk[$i]->coal_washery;
  1427. $result['data'][$i]['place'] = $risk[$i]->work_location;
  1428. $result['data'][$i]['content'] = $risk[$i]->risk_name;
  1429. }
  1430. }
  1431. return self::successResponse($result);
  1432. }
  1433. //风险作业详情
  1434. public function riskWorkDetail(Request $request){
  1435. $params = $request->all();
  1436. if (!isset($params['id'])) {
  1437. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1438. }
  1439. $risk_type = ['高空坠落','起重伤害','触电','火灾','机械伤害','中毒和窒息'];
  1440. $risk_level = ['高风险','中风险','低风险'];
  1441. $risk = DB::connection('task_xixuan')->table('xx_risk_assignment')
  1442. ->select('xx_risk_assignment.*','xx_coal_washery.name as coal_washery')
  1443. ->leftJoin('xx_coal_washery','xx_coal_washery.id','=','xx_risk_assignment.coal_washery_id')
  1444. ->where('xx_risk_assignment.id',$params['id'])->get();
  1445. if(count($risk) > 0){
  1446. $camera_info = explode('|',$risk[0]->camera_id);
  1447. $is_hak = MineListExt::where('mine_id', $camera_info[1])->value('is_hak');
  1448. if($is_hak == 2){
  1449. $type = 'rtsp';
  1450. }else{
  1451. $type = 'm3u8';
  1452. }
  1453. if($risk[0]->risk_type != '' && $risk[0]->risk_type !=null){
  1454. $risk_type_value = $risk_type[$risk[0]->risk_type];
  1455. }else{
  1456. $risk_type_value = '';
  1457. }
  1458. $result['detail'] = [
  1459. [
  1460. 'label' => '风险类型:',
  1461. 'value' => $risk_type_value
  1462. ],
  1463. [
  1464. 'label' => '风险等级:',
  1465. 'value' => $risk_level[$risk[0]->risk_level]
  1466. ],
  1467. [
  1468. 'label' => '单位:',
  1469. 'value' => $risk[0]->coal_washery
  1470. ],
  1471. [
  1472. 'label' => '风险作业内容:',
  1473. 'value' => $risk[0]->risk_name
  1474. ],
  1475. [
  1476. 'label' => '人数:',
  1477. 'value' => $risk[0]->work_num
  1478. ],
  1479. [
  1480. 'label' => '地点:',
  1481. 'value' => $risk[0]->work_location
  1482. ],
  1483. [
  1484. 'label' => '现场负责人:',
  1485. 'value' => $risk[0]->work_people
  1486. ],
  1487. [
  1488. 'label' => '摄像头类型:',
  1489. 'value' => CameraEnum::CAMERA_TYPE_EXCHANGE[$camera_info[3]]
  1490. ],
  1491. ];
  1492. $camera_id = explode('|',$risk[0]->camera_id);
  1493. $result['camera']['camera_id'] = $camera_id[0];
  1494. $result['camera']['parent_id'] = $camera_id[1];
  1495. $result['camera']['camera_type'] = $type;
  1496. }
  1497. return self::successResponse($result);
  1498. }
  1499. //首頁信息
  1500. public function taskHome(Request $request){
  1501. $risk_type = ['高空坠落','起重伤害','触电','火灾','机械伤害','中毒和窒息'];
  1502. $risk_level = ['高风险','中风险','低风险'];
  1503. //高风险作业
  1504. $gaofengxian = DB::connection('task_xixuan')->table('xx_risk_assignment')
  1505. ->select('xx_risk_assignment.*','xx_coal_washery.name as coal_washery')
  1506. ->leftJoin('xx_coal_washery','xx_coal_washery.id','=','xx_risk_assignment.coal_washery_id')
  1507. ->whereDate('xx_risk_assignment.optdt', today())
  1508. ->where('risk_level',0)->get();
  1509. if(count($gaofengxian) > 0){
  1510. for($i=0;$i<count($gaofengxian);$i++){
  1511. if($gaofengxian[$i]->risk_type == ''){
  1512. $gaofengxian[$i]->risk_type_name = '无';
  1513. }else{
  1514. $gaofengxian[$i]->risk_type_name = $risk_type[$gaofengxian[$i]->risk_type];
  1515. }
  1516. $camera_info = explode('|',$gaofengxian[$i]->camera_id);
  1517. $gaofengxian[$i]->camera_type = CameraEnum::CAMERA_TYPE_EXCHANGE[$camera_info[3]];
  1518. $gaofengxian[$i]->risk_level_name = $risk_level[$gaofengxian[$i]->risk_level];
  1519. }
  1520. }
  1521. $result['gao_count'] = count($gaofengxian);
  1522. $result['gao'] = $gaofengxian;
  1523. //中风险作业
  1524. $zhongfengxian = DB::connection('task_xixuan')->table('xx_risk_assignment')
  1525. ->select('xx_risk_assignment.*','xx_coal_washery.name as coal_washery')
  1526. ->leftJoin('xx_coal_washery','xx_coal_washery.id','=','xx_risk_assignment.coal_washery_id')
  1527. ->whereDate('xx_risk_assignment.optdt', today())
  1528. ->where('risk_level',1)->get();
  1529. if(count($zhongfengxian) > 0){
  1530. for($i=0;$i<count($zhongfengxian);$i++){
  1531. if($zhongfengxian[$i]->risk_type == ''){
  1532. $zhongfengxian[$i]->risk_type_name = '无';
  1533. }else{
  1534. $zhongfengxian[$i]->risk_type_name = $risk_type[$zhongfengxian[$i]->risk_type];
  1535. }
  1536. $camera_info = explode('|',$zhongfengxian[$i]->camera_id);
  1537. $zhongfengxian[$i]->camera_type = CameraEnum::CAMERA_TYPE_EXCHANGE[$camera_info[3]];
  1538. $zhongfengxian[$i]->risk_level_name = $risk_level[$zhongfengxian[$i]->risk_level];
  1539. }
  1540. }
  1541. $result['zhong_count'] = count($zhongfengxian);
  1542. $result['zhong'] = $zhongfengxian;
  1543. //低风险作业
  1544. $difengxian = DB::connection('task_xixuan')->table('xx_risk_assignment')
  1545. ->select('xx_risk_assignment.*','xx_coal_washery.name as coal_washery')
  1546. ->leftJoin('xx_coal_washery','xx_coal_washery.id','=','xx_risk_assignment.coal_washery_id')
  1547. ->whereDate('xx_risk_assignment.optdt', today())
  1548. ->where('risk_level',2)->get();
  1549. if(count($difengxian) > 0){
  1550. for($i=0;$i<count($difengxian);$i++){
  1551. if($difengxian[$i]->risk_type == ''){
  1552. $difengxian[$i]->risk_type_name = '无';
  1553. }else{
  1554. $difengxian[$i]->risk_type_name = $risk_type[$difengxian[$i]->risk_type];
  1555. }
  1556. $camera_info = explode('|',$difengxian[$i]->camera_id);
  1557. $difengxian[$i]->camera_type = CameraEnum::CAMERA_TYPE_EXCHANGE[$camera_info[3]];
  1558. $difengxian[$i]->risk_level_name = $risk_level[$difengxian[$i]->risk_level];
  1559. }
  1560. }
  1561. $result['di_count'] = count($difengxian);
  1562. $result['di'] = $difengxian;
  1563. //片区作业数
  1564. $area = DB::connection('task_xixuan')->table('xx_area')->get();
  1565. $result['area_count'] = [];
  1566. if(count($area) > 0){
  1567. for($i=0;$i<count($area);$i++){
  1568. $result['area_count'][$i]['name'] = $area[$i]->name;
  1569. $coal_washery_id_list = DB::connection('task_xixuan')->table('xx_coal_washery')->where('area_id',$area[$i]->id)->pluck('id');
  1570. $result['area_count'][$i]['count'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('optdt', today())->count();
  1571. }
  1572. }
  1573. //洗煤厂作业
  1574. $coal_washery = DB::connection('task_xixuan')->table('xx_coal_washery')->get();
  1575. $result['coal_washery_work_count'] = [];
  1576. if(count($coal_washery) > 0){
  1577. for($i=0;$i<count($coal_washery);$i++){
  1578. $result['coal_washery_work_count'][$i]['name'] = $coal_washery[$i]->name;
  1579. $result['coal_washery_work_count'][$i]['gao'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->id)->where('risk_level',0)->whereDate('optdt', today())->count();
  1580. $result['coal_washery_work_count'][$i]['zhong'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->id)->where('risk_level',1)->whereDate('optdt', today())->count();
  1581. $result['coal_washery_work_count'][$i]['di'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->id)->where('risk_level',2)->whereDate('optdt', today())->count();
  1582. }
  1583. }
  1584. //7天作业数
  1585. $result['seven_work_count'] = [];
  1586. for($i=0;$i<7;$i++){
  1587. $day = date('Y-m-d', strtotime('-'.$i.' day'));
  1588. $result['seven_work_count'][$i]['date'] = $day;
  1589. $result['seven_work_count'][$i]['gao'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $day)->where('risk_level',0)->count();
  1590. $result['seven_work_count'][$i]['zhong'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $day)->where('risk_level',1)->count();
  1591. $result['seven_work_count'][$i]['di'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $day)->where('risk_level',2)->count();
  1592. }
  1593. //7天片区作业数
  1594. $result['seven_area_work_count'] = [];
  1595. if(count($area) > 0){
  1596. for($i=0;$i<count($area);$i++){
  1597. $result['seven_area_work_count'][$i]['name'] = $area[$i]->name;
  1598. $result['seven_area_work_count'][$i]['area_id'] = $area[$i]->id;
  1599. for($j=0;$j<7;$j++){
  1600. $day = date('Y-m-d', strtotime('-'.$j.' day'));
  1601. $result['seven_area_work_count'][$i]['work'][$j]['date'] = $day;
  1602. $coal_washery_id_list = DB::connection('task_xixuan')->table('xx_coal_washery')->where('area_id',$area[$i]->id)->pluck('id');
  1603. $result['seven_area_work_count'][$i]['work'][$j]['gao'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('optdt', $day)->where('risk_level',0)->count();
  1604. $result['seven_area_work_count'][$i]['work'][$j]['zhong'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('optdt', $day)->where('risk_level',1)->count();
  1605. $result['seven_area_work_count'][$i]['work'][$j]['di'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('optdt', $day)->where('risk_level',2)->count();
  1606. }
  1607. }
  1608. }
  1609. return self::successResponse($result);
  1610. }
  1611. //首页作业查询
  1612. public function workSearch(Request $request){
  1613. $params = $request->all();
  1614. if (!isset($params['start_date'])) {
  1615. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1616. }
  1617. if (!isset($params['end_date'])) {
  1618. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1619. }
  1620. $result = [];
  1621. $start_date = $params['start_date'];
  1622. $end_date = $params['end_date'];
  1623. $current_date = $start_date;
  1624. $i = 0;
  1625. while ($current_date <= $end_date) {
  1626. $result[$i]['date'] = $current_date;
  1627. $result[$i]['gao'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $current_date)->where('risk_level',0)->count();
  1628. $result[$i]['zhong'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $current_date)->where('risk_level',1)->count();
  1629. $result[$i]['di'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $current_date)->where('risk_level',2)->count();
  1630. $current_date = date('Y-m-d', strtotime($current_date . ' +1 day'));
  1631. $i++;
  1632. }
  1633. return self::successResponse($result);
  1634. }
  1635. //首页片区作业查询
  1636. public function areaWorkSearch(Request $request){
  1637. $params = $request->all();
  1638. if (!isset($params['start_date'])) {
  1639. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1640. }
  1641. if (!isset($params['end_date'])) {
  1642. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1643. }
  1644. if (!isset($params['area_id'])) {
  1645. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1646. }
  1647. $coal_washery_id_list = DB::connection('task_xixuan')->table('xx_coal_washery')->where('area_id',$params['area_id'])->pluck('id');
  1648. $result = [];
  1649. $start_date = $params['start_date'];
  1650. $end_date = $params['end_date'];
  1651. $current_date = $start_date;
  1652. $i = 0;
  1653. while ($current_date <= $end_date) {
  1654. $result[$i]['date'] = $current_date;
  1655. $result[$i]['gao'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('optdt', $current_date)->where('risk_level',0)->count();
  1656. $result[$i]['zhong'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('optdt', $current_date)->where('risk_level',1)->count();
  1657. $result[$i]['di'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('optdt', $current_date)->where('risk_level',2)->count();
  1658. $current_date = date('Y-m-d', strtotime($current_date . ' +1 day'));
  1659. $i++;
  1660. }
  1661. return self::successResponse($result);
  1662. }
  1663. }