CameraApiController.php 78 KB

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