CameraApiController.php 178 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266
  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. $data = [];
  67. $type = Input::get('type', '');
  68. //宁煤集团
  69. $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
  70. $mine_all = DB::table('mine_list')->where('deleted_at',null);
  71. $xczyd = DB::table('mine_list')->where('deleted_at',null)->where('title','现场作业点')->pluck('degree');
  72. $ydjk = DB::table('mine_list')->where('deleted_at',null)->where('title','移动监控')->pluck('degree');
  73. if(count($xczyd) > 0){
  74. for($i=0;$i<count($xczyd);$i++){
  75. $mine_all->where('degree','not like',$xczyd[$i].'%');
  76. }
  77. }
  78. if(count($ydjk) > 0){
  79. for($i=0;$i<count($ydjk);$i++){
  80. $mine_all->where('degree','not like',$ydjk[$i].'%');
  81. }
  82. }
  83. $mine_all = $mine_all->get();
  84. // $mine_all = DB::table('mine_list')->where('deleted_at',null)->whereNotIn('id',$ydjk_list)->whereNotIn('id',$xczyd_list)->get();//所有区域
  85. // $mine_all = DB::table('mine_list')->where('deleted_at',null)->where('degree','not like','968|2447|5784%')->where('degree','not like','968|2525|6477%')->where('degree','not like','968|2576|6825%')->where('degree','not like','968|2576|6808%')->get();//所有区域
  86. $mine_ningmei = [];//宁煤集团所有区域
  87. foreach($mine_all as $k=>$v){
  88. if(explode('|',$v->degree)[0] == $ningmei[0]->id){
  89. $mine_ningmei[] = $v->id;
  90. }
  91. }
  92. if($type == 'nmjt' || $type == ''){
  93. //宁煤在离线数量
  94. $data[0]['title'] = '宁煤公司';
  95. $data[0]['mine_code'] = $ningmei[0]->slug;
  96. $data[0]['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('deleted_at',null)->count();
  97. $data[0]['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('camera_status',1)->where('deleted_at',null)->count();
  98. $data[0]['total_offline'] = $data[0]['total'] - $data[0]['total_online'];
  99. $data[0]['rate'] = round($data[0]['total_online'] / $data[0]['total'] * 100,2)."%";
  100. }
  101. if($type == 'nmjt'){
  102. return self::successResponse($data);
  103. }
  104. //宁煤下各矿在离线数量
  105. if($type == 'mtdw'){
  106. $where = ['1941', '1982', '2019', '2099', '2160', '2181', '2193', '2226', '2258', '2307', '2308', '2323', '2324', '2345', '2376', '2405', '2923', '2427', '2429', '6157'];
  107. $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->whereIn('id',$where)->where('deleted_at',null)->get();
  108. }elseif($type == 'hgdw'){
  109. $where = ['2447', '2525', '2557', '2576', '3868', '2597', '3452'];
  110. $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->whereIn('id',$where)->where('deleted_at',null)->get();
  111. }elseif($type == 'ndtl'){
  112. $where = ['6001'];
  113. $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->whereIn('id',$where)->where('deleted_at',null)->get();
  114. }elseif($type == 'qtdw'){
  115. $where = ['2628', '2599', '2600', '2611', '3167'];
  116. $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->whereIn('id',$where)->where('deleted_at',null)->get();
  117. }elseif($type == 'gfx'){
  118. $where = ['4272'];
  119. $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->whereIn('id',$where)->where('deleted_at',null)->get();
  120. }else{
  121. $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('deleted_at',null)->get();
  122. }
  123. foreach($mine_list as $k => $v){
  124. $mine_use = [];//宁煤下每个矿所有区域
  125. foreach($mine_all as $key=>$value){
  126. if(count(explode('|',$value->degree)) > 1){
  127. if(explode('|',$value->degree)[0] == $ningmei[0]->id && explode('|',$value->degree)[1] == $v->id){
  128. $mine_use[] = $value->id;
  129. }
  130. }
  131. }
  132. $total = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('deleted_at',null)->count();
  133. $total_online = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('camera_status',1)->where('deleted_at',null)->count();
  134. if($total == 0){
  135. $rate = "0%";
  136. }else{
  137. $rate = round($total_online / $total * 100,2)."%";
  138. }
  139. if($v->slug == 'NingXiaMeiYeTeShuZuoYeJianKongShiPin'){
  140. $res['title'] = $v->title;
  141. $res['mine_code'] = $v->slug."_jituan";
  142. $res['total'] = $total;
  143. $res['total_online'] = $total_online;
  144. $res['total_offline'] = $total - $total_online;
  145. $res['rate'] = $rate;
  146. }else{
  147. if($v->slug == 'ShuiDianFenGongSi'){
  148. $v->title = '供电分公司';
  149. }
  150. array_push($data,[
  151. 'title'=>$v->title,
  152. 'mine_code'=>$v->slug."_jituan",
  153. 'total'=>$total,
  154. 'total_online'=>$total_online,
  155. 'total_offline'=>$total - $total_online,
  156. 'rate'=>$rate
  157. ]);
  158. }
  159. }
  160. if(isset($res)){
  161. array_push($data,[
  162. 'title'=>$res['title'],
  163. 'mine_code'=>$res['mine_code'],
  164. 'total'=>$res['total'],
  165. 'total_online'=>$res['total_online'],
  166. 'total_offline'=>$res['total_offline'],
  167. 'rate'=>$res['rate']
  168. ]);
  169. }
  170. return self::successResponse($data);
  171. }
  172. //宁煤摄像头周统计
  173. public function getTotalNingmeiWeek(){
  174. $result['status'] = true;
  175. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  176. $type = Input::get('type', '');
  177. $data = [];
  178. if($type == 'nmjt' || $type == ''){
  179. $list = DB::table('camera_status_history')->where('title','宁煤公司')->where('date', '>=', date('Y-m-d H:i:s', strtotime('-7 days')))->get();
  180. $total = 0;
  181. $total_online = 0;
  182. $totle_offline = 0;
  183. $rate = 0;
  184. if(count($list) > 0){
  185. for($i=0;$i<count($list);$i++){
  186. $total = $total + $list[$i]->total;
  187. $total_online = $total_online + $list[$i]->total_online;
  188. $totle_offline = $totle_offline + $list[$i]->total_offline;
  189. $rate = $rate + $list[$i]->rate;
  190. }
  191. array_push($data,[
  192. 'title'=> $list[0]->title,
  193. 'mine_code'=> $list[0]->mine_code,
  194. 'total'=> round($total/count($list),2),
  195. 'total_online'=> round($total_online/count($list),2),
  196. 'total_offline'=> round($totle_offline/count($list),2),
  197. 'rate'=> round($rate/count($list),2).'%'
  198. ]);
  199. }
  200. }
  201. if($type == 'nmjt'){
  202. return self::successResponse($data);
  203. }
  204. $id_list = [];
  205. //宁煤下各矿在离线数量
  206. if($type == 'mtdw'){
  207. $id_list = ['1941', '1982', '2019', '2099', '2160', '2181', '2193', '2226', '2258', '2307', '2308', '2323', '2324', '2345', '2376', '2405', '2923', '2427', '2429', '6157'];
  208. }elseif($type == 'hgdw'){
  209. $id_list = ['2447', '2525', '2557', '2576', '3868', '2597', '3452'];
  210. }elseif($type == 'ndtl'){
  211. $id_list = ['6001'];
  212. }elseif($type == 'qtdw'){
  213. $id_list = ['2628', '2599', '2600', '2611', '3167'];
  214. }elseif($type == 'gfx'){
  215. $id_list = ['4272'];
  216. }else{
  217. $id_list = ['1941', '1982', '2019', '2099', '2160', '2181', '2193', '2226', '2258', '2307', '2308', '2323', '2324', '2345', '2376', '2405', '2923', '2427', '2429', '6157','2447', '2525', '2557', '2576', '3868', '2597', '3452','6001','2628', '2599', '2600', '2611', '3167','4272'];
  218. }
  219. $unit_list = DB::table('mine_list')->whereIn('id',$id_list)->pluck('title');
  220. if(count($unit_list) > 0){
  221. for($i=0;$i<count($unit_list);$i++){
  222. $list = DB::table('camera_status_history')->where('title',$unit_list[$i])->where('date', '>=', date('Y-m-d H:i:s', strtotime('-7 days')))->get();
  223. $total = 0;
  224. $total_online = 0;
  225. $totle_offline = 0;
  226. $rate = 0;
  227. if(count($list) > 0){
  228. for($j=0;$j<count($list);$j++){
  229. $total = $total + $list[$j]->total;
  230. $total_online = $total_online + $list[$j]->total_online;
  231. $totle_offline = $totle_offline + $list[$j]->total_offline;
  232. $rate = $rate + $list[$j]->rate;
  233. }
  234. array_push($data,[
  235. 'title'=> $unit_list[$i],
  236. 'mine_code'=> $list[0]->mine_code,
  237. 'total'=> round($total/count($list),2),
  238. 'total_online'=> round($total_online/count($list),2),
  239. 'total_offline'=> round($totle_offline/count($list),2),
  240. 'rate'=> round($rate/count($list),2).'%'
  241. ]);
  242. }
  243. }
  244. }
  245. return self::successResponse($data);
  246. }
  247. //宁煤摄像头统计字符串
  248. public function getTotalString(){
  249. $result['status'] = true;
  250. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  251. //宁煤集团
  252. $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
  253. $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
  254. $mine_ningmei = [];//宁煤集团所有区域
  255. foreach($mine_all as $k=>$v){
  256. if(explode('|',$v->degree)[0] == $ningmei[0]->id){
  257. $mine_ningmei[] = $v->id;
  258. }
  259. }
  260. //宁煤在离线数量
  261. $nm['title'] = '宁煤公司';
  262. $nm['mine_code'] = $ningmei[0]->slug;
  263. $nm['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('deleted_at',null)->count();
  264. $nm['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('camera_status',1)->where('deleted_at',null)->count();
  265. $nm['total_offline'] = $nm['total'] - $nm['total_online'];
  266. $nm['rate'] = round($nm['total_online'] / $nm['total'] * 100,2);
  267. $data = [];
  268. //宁煤下各矿在离线数量
  269. $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('deleted_at',null)->get();
  270. foreach($mine_list as $k => $v){
  271. $mine_use = [];//宁煤下每个矿所有区域
  272. foreach($mine_all as $key=>$value){
  273. if(count(explode('|',$value->degree)) > 1){
  274. if(explode('|',$value->degree)[0] == $ningmei[0]->id && explode('|',$value->degree)[1] == $v->id){
  275. $mine_use[] = $value->id;
  276. }
  277. }
  278. }
  279. $total = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('deleted_at',null)->count();
  280. $total_online = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('camera_status',1)->where('deleted_at',null)->count();
  281. if($total == 0){
  282. $rate = "0";
  283. }else{
  284. $rate = round($total_online / $total * 100,2);
  285. }
  286. if($v->slug == 'NingXiaMeiYeTeShuZuoYeJianKongShiPin'){
  287. $res['title'] = $v->title;
  288. $res['mine_code'] = $v->slug."_jituan";
  289. $res['total'] = $total;
  290. $res['total_online'] = $total_online;
  291. $res['total_offline'] = $total - $total_online;
  292. $res['rate'] = $rate;
  293. }else{
  294. array_push($data,[
  295. 'title'=>$v->title,
  296. 'mine_code'=>$v->slug."_jituan",
  297. 'total'=>$total,
  298. 'total_online'=>$total_online,
  299. 'total_offline'=>$total - $total_online,
  300. 'rate'=>$rate
  301. ]);
  302. }
  303. }
  304. if(isset($res)){
  305. array_push($data,[
  306. 'title'=>$res['title'],
  307. 'mine_code'=>$res['mine_code'],
  308. 'total'=>$res['total'],
  309. 'total_online'=>$res['total_online'],
  310. 'total_offline'=>$res['total_offline'],
  311. 'rate'=>$res['rate']
  312. ]);
  313. }
  314. $timestamp = strtotime(date('Y-m-d H:i:s'));
  315. $hour = date('G', $timestamp);
  316. $minute = date('i', $timestamp);
  317. $month = date('n', $timestamp);
  318. $day = date('j', $timestamp);
  319. if($minute == '00'){
  320. $minute = '';
  321. }
  322. if ($hour < 12) {
  323. $time = $month."月".$day."号上午".$hour."时".$minute;
  324. } elseif ($hour >= 12 && $hour < 18) {
  325. $time = $month."月".$day."号下午".$hour."时".$minute;
  326. } else {
  327. $time = $month."月".$day."号晚上".$hour."时".$minute;
  328. }
  329. $unit_max_name = '';
  330. $unit_max_rate = 0;
  331. $unit_min_name = '';
  332. $unit_min_rate = 100;
  333. $mzy_max_name = '';
  334. $mzy_max_rate = 0;
  335. $mzy_min_name = '';
  336. $mzy_min_rate = 100;
  337. $other_max_name = '';
  338. $other_max_rate = 0;
  339. $other_min_name = '';
  340. $other_min_rate = 100;
  341. if(count($data)>0){
  342. for($i=0;$i<count($data);$i++){
  343. if (strpos($data[$i]['title'], '煤矿') !== false || strpos($data[$i]['title'], '洗选') !== false) {
  344. if($data[$i]['rate'] > $unit_max_rate){
  345. $unit_max_rate = $data[$i]['rate'];
  346. }
  347. if($data[$i]['rate'] < $unit_min_rate){
  348. $unit_min_rate = $data[$i]['rate'];
  349. }
  350. }elseif(strpos($data[$i]['title'], '煤制油') !== false || strpos($data[$i]['title'], '烯烃') !== false || strpos($data[$i]['title'], '甲醇') !== false || strpos($data[$i]['title'], '精蜡') !== false){
  351. if($data[$i]['rate'] > $mzy_max_rate){
  352. $mzy_max_rate = $data[$i]['rate'];
  353. }
  354. if($data[$i]['rate'] < $mzy_min_rate){
  355. $mzy_min_rate = $data[$i]['rate'];
  356. }
  357. }else{
  358. if($data[$i]['rate'] > $other_max_rate){
  359. $other_max_rate = $data[$i]['rate'];
  360. }
  361. if($data[$i]['rate'] < $other_min_rate){
  362. $other_min_rate = $data[$i]['rate'];
  363. }
  364. }
  365. }
  366. for($i=0;$i<count($data);$i++){
  367. if (strpos($data[$i]['title'], '煤矿') !== false || strpos($data[$i]['title'], '洗选') !== false) {
  368. if($data[$i]['rate'] == $unit_max_rate){
  369. $unit_max_name = $unit_max_name.'、'.$data[$i]['title'];
  370. }
  371. if($data[$i]['rate'] == $unit_min_rate){
  372. $unit_min_name = $unit_max_name.'、'.$data[$i]['title'];
  373. }
  374. }elseif(strpos($data[$i]['title'], '煤制油') !== false || strpos($data[$i]['title'], '烯烃') !== false || strpos($data[$i]['title'], '甲醇') !== false || strpos($data[$i]['title'], '精蜡') !== false){
  375. if($data[$i]['rate'] == $mzy_max_rate){
  376. $mzy_max_name = $mzy_max_name.'、'.$data[$i]['title'];
  377. }
  378. if($data[$i]['rate'] == $mzy_min_rate){
  379. $mzy_min_name = $mzy_max_name.'、'.$data[$i]['title'];
  380. }
  381. }else{
  382. if($data[$i]['rate'] == $other_max_rate){
  383. $other_max_name = $other_max_name.'、'.$data[$i]['title'];
  384. }
  385. if($data[$i]['rate'] == $other_min_rate){
  386. $other_min_name = $other_max_name.'、'.$data[$i]['title'];
  387. }
  388. }
  389. }
  390. }
  391. $unit_max_name = mb_substr($unit_max_name, 1);
  392. $unit_min_name = mb_substr($unit_min_name, 1);
  393. $mzy_max_name = mb_substr($mzy_max_name, 1);
  394. $mzy_min_name = mb_substr($mzy_min_name, 1);
  395. $other_max_name = mb_substr($other_max_name, 1);
  396. $other_min_name = mb_substr($other_min_name, 1);
  397. $result['data'] = '本周公司视频摄像头在线数'.$nm['total_online'].'个,'.'在线率为'.$nm['rate'].'%('.$time
  398. .'统计)。其中:①煤炭生产建设单位在线率排名第一的单位是'.$unit_max_name.',在线率达到'.$unit_max_rate
  399. .'%;排名末位的单位是'.$unit_min_name.',在线率达到'.$unit_min_rate
  400. .'%。②煤制油化工单位在线率排名第一的单位是'.$mzy_max_name.',在线率达到'.$mzy_max_rate.'%;排名末位的单位是'
  401. .$mzy_min_name.',在线率达到'.$mzy_min_rate.'%。③其他单位在线率排名第一的单位是'.$other_max_name
  402. .',在线率达到'.$other_max_rate.'%;排名末位的单位是'.$other_min_name.',在线率达到'.$other_min_rate.'%。';
  403. return self::successResponse($result);
  404. }
  405. //宁煤不在线摄像头列表
  406. public function offlineList(){
  407. $mine_code = Input::get('mine_code', '');
  408. if (!$mine_code) {
  409. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  410. }
  411. $result['status'] = true;
  412. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  413. //宁煤集团
  414. $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
  415. $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
  416. $mine_ningmei = [];//宁煤集团所有区域
  417. foreach($mine_all as $k=>$v){
  418. if(explode('|',$v->degree)[0] == $ningmei[0]->id){
  419. $mine_ningmei[] = $v->id;
  420. }
  421. }
  422. if(count(explode('_',$mine_code)) > 1){
  423. $mine_code = explode('_',$mine_code)[0];
  424. }
  425. $mine_list = DB::table('mine_list')->where('parent_id',0)->where('slug','like','%'.$mine_code.'%')->where('deleted_at',null)->get();
  426. //如果传参是宁煤显示全部
  427. if(isset($mine_list[0]->title) && $mine_list[0]->title == config('mine_hls')[0]){
  428. //宁煤在离线数量
  429. $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();
  430. return self::successResponse($offline_list);
  431. }
  432. //宁煤下各矿在离线数量
  433. $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('slug','like','%'.$mine_code.'%')->where('deleted_at',null)->get();
  434. $total_offline = [];
  435. foreach($mine_list as $k => $v){
  436. $mine_use = [];//宁煤下每个矿所有区域
  437. foreach($mine_all as $key=>$value){
  438. if(count(explode('|',$value->degree)) > 1){
  439. if(explode('|',$value->degree)[0] == $ningmei[0]->id && explode('|',$value->degree)[1] == $v->id){
  440. $mine_use[] = $value->id;
  441. }
  442. }
  443. }
  444. $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();
  445. }
  446. return self::successResponse($total_offline);
  447. }
  448. //宁煤高风险摄像头
  449. public function getRiskNingmei(){
  450. $mine_code = Input::get('mine_code', '');
  451. if (!$mine_code) {
  452. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  453. }
  454. $result['status'] = true;
  455. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  456. //宁煤集团
  457. $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
  458. //宁煤集团下级单位
  459. $mine = DB::table('mine_list')
  460. ->where('parent_id',$ningmei[0]->id)
  461. ->where('slug','like','%'.$mine_code.'%')
  462. ->where('deleted_at',null)
  463. ->get();
  464. //子区域树形列表
  465. $child_list = DB::table('mine_list')->where('parent_id',$mine[0]->id)->where('deleted_at',null)->orderBy('sort','desc')->get();
  466. $risk_id = null;
  467. if(count($child_list)>0){
  468. $risk_id = $this->mineTree($child_list);
  469. }
  470. $mine_list = [];
  471. if($risk_id != null){
  472. $risk = DB::table('mine_list')->where('parent_id',$risk_id)->where('deleted_at',null)->get();
  473. if(count($risk) > 0){
  474. //有子区域
  475. $mine_list = $this->riskTree($risk,[]);
  476. }else{
  477. //没有子区域
  478. $mine_list[] = $risk_id;
  479. }
  480. }
  481. $camera_list = DB::table('camera_list')
  482. ->select('camera_list.*','mine_list.title')
  483. ->leftJoin('mine_list','camera_list.mine_id','=','mine_list.id')
  484. ->where('camera_list.deleted_at',null)
  485. ->whereIn('camera_list.mine_id',$mine_list)
  486. ->orderBy('sort', 'desc')->get();
  487. $result = [];
  488. foreach($camera_list as $k=>$v){
  489. $result[$k]['parent_id'] = $ningmei[0]->id;
  490. $result[$k]['camera_id'] = $v->id;
  491. $result[$k]['mine_name'] = $v->title;
  492. $result[$k]['camera_name'] = $v->camera_name;
  493. $result[$k]['cover_picture'] = $v->cover_picture;
  494. $result[$k]['camera_status'] = $v->camera_status;
  495. $result[$k]['base64'] = $v->base64;
  496. }
  497. return self::successResponse($result);
  498. }
  499. public function mineTree($regions)
  500. {
  501. $arr = null;
  502. foreach ($regions as $key => $value) {
  503. $risk = explode('高风险作业',$value->title);
  504. if (count($risk)>1){
  505. return $value->id;
  506. }
  507. $mine_child = DB::table('mine_list')->where('parent_id', $value->id)->where('deleted_at',null)->get();
  508. if (count($mine_child) > 0) {
  509. $arr = self::mineTree($mine_child, $value->id);
  510. if($arr != null){
  511. return $arr;
  512. }
  513. }
  514. }
  515. return $arr;
  516. }
  517. public function riskTree($regions,$risk_list)
  518. {
  519. foreach ($regions as $key => $value) {
  520. $risk_child = DB::table('mine_list')->where('parent_id', $value->id)->where('deleted_at',null)->get();
  521. if (count($risk_child) > 0) {
  522. $risk_list = array_merge($risk_list,self::riskTree($risk_child,[]));
  523. }else{
  524. $risk_list[] = $value->id;
  525. }
  526. }
  527. return $risk_list;
  528. }
  529. //高风险区域摄像头
  530. public function getCameraByMinecode(){
  531. $mine_code = Input::get('mine_code', '');
  532. if (!$mine_code) {
  533. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  534. }
  535. $result['status'] = true;
  536. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  537. $mine = DB::table('mine_list')->where('slug','like','%'.$mine_code.'%')->where('parent_id',0)->where('deleted_at',null)->first();
  538. if (!$mine) {
  539. $result['status'] = false;
  540. $result['msg'] = '矿区名称不存在';
  541. return $result;
  542. }
  543. $mine_list = DB::table('mine_list')->where('degree', 'like', $mine->id . '|' . '%')->where('title','like','%高风险%')->where('deleted_at',null)->get();
  544. $mine_array = [];
  545. foreach($mine_list as $k=>$v){
  546. $mine_child = DB::table('mine_list')->where('degree', 'like','%' . $v->id . '%')->where('deleted_at',null)->get();
  547. if(count($mine_child)>0){
  548. for($i=0;$i<count($mine_child);$i++){
  549. $mine_array[] = $mine_child[$i]->id;
  550. }
  551. }
  552. }
  553. $query = DB::table('camera_list')
  554. ->select('camera_list.*','mine_list.title')
  555. ->leftJoin('mine_list','camera_list.mine_id','=','mine_list.id')
  556. ->where('camera_list.deleted_at',null)
  557. ->whereIn('camera_list.mine_id',$mine_array)
  558. ->orderBy('sort', 'desc')->get();
  559. if (!$query) {
  560. $result['status'] = false;
  561. $result['msg'] = '矿区下没有摄像头';
  562. return $result;
  563. }
  564. $result = [];
  565. foreach($query as $k=>$v){
  566. $result[$k]['parent_id'] = $mine->id;
  567. $result[$k]['camera_id'] = $v->id;
  568. $result[$k]['mine_name'] = $v->title;
  569. $result[$k]['camera_name'] = $v->camera_name;
  570. $result[$k]['cover_picture'] = $v->cover_picture;
  571. $result[$k]['camera_status'] = $v->camera_status;
  572. }
  573. return self::successResponse($result);
  574. }
  575. /**
  576. * 作者: qiuzijian
  577. * 注释: 获取摄像头列表
  578. * @return \App\Http\Controllers\Api\JsonResponse
  579. */
  580. public function getCamerasList()
  581. {
  582. $parent_id = Input::get('parent_id', '');
  583. $mine_id = Input::get('mine_id', '');
  584. $camera_type = Input::get('camera_type', CameraEnum::CAMERA_TYPE_ALL);
  585. $surface_id = Input::get('surface_id', '');
  586. if (!$parent_id) {
  587. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  588. }
  589. if (!in_array($camera_type, [CameraEnum::CAMERA_TYPE_NORMAL, CameraEnum::CAMERA_TYPE_ALL]) && !$surface_id) {
  590. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  591. }
  592. //判断是否使用海康视频服务器
  593. // $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
  594. // if ($is_hak) {
  595. // $result = CameraServices::getHaiKangCamera($parent_id, $mine_id, $camera_type);
  596. // } else {
  597. $result = CameraServices::getCameraListByMineId($mine_id, $camera_type, $parent_id, $surface_id);
  598. // }
  599. return self::successResponse($result);
  600. }
  601. //大华语音对讲
  602. public function dahuaTalk(){
  603. $parent_id = Input::get('parent_id', '');
  604. $camera_id = Input::get('camera_id', '');
  605. if (!$parent_id || !$camera_id) {
  606. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  607. }
  608. $tdwy = new TdwyController();
  609. $result = $tdwy->talkUrl($camera_id,$parent_id);
  610. return self::successResponse($result);
  611. }
  612. //海康语音对讲
  613. public function hikTalk(){
  614. $parent_id = Input::get('parent_id', '');
  615. $camera_id = Input::get('camera_id', '');
  616. if (!$parent_id || !$camera_id) {
  617. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  618. }
  619. $result['status'] = true;
  620. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  621. $result = CameraServices::getHikTalkUrl($parent_id,$camera_id);
  622. return self::successResponse($result);
  623. }
  624. //大华停止语音对讲
  625. public function dahuaStopTalk(){
  626. $parent_id = Input::get('parent_id', '');
  627. $camera_id = Input::get('camera_id', '');
  628. $device_code = Input::get('device_code', '');
  629. $session = Input::get('session', '');
  630. if (!$parent_id || !$camera_id || !$device_code || !$session) {
  631. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  632. }
  633. $tdwy = new TdwyController();
  634. $result = $tdwy->talkStop($camera_id,$parent_id,$device_code,$session);
  635. return self::successResponse($result);
  636. }
  637. /**
  638. * 作者: qiuzijian
  639. * 注释: 获取摄像头播放地址
  640. * @return \App\Http\Controllers\Api\JsonResponse
  641. */
  642. public function getCamerasUrl()
  643. {
  644. $parent_id = Input::get('parent_id', '');
  645. $camera_id = Input::get('camera_id', '');
  646. if (!$parent_id || !$camera_id) {
  647. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  648. }
  649. //判断摄像头来源是否为内网服务器
  650. $camera_source = CameraList::where('id', $camera_id)->value('camera_source');
  651. if ($camera_source == CameraEnum::CAMERA_SOURCE_3) {
  652. $result = CameraServices::getIntranetCameraUrl($camera_id);
  653. return self::successResponse($result);
  654. }
  655. //判断是否使用海康视频服务器
  656. $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
  657. //判断是否生成摄像头请求链接
  658. $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
  659. if ($is_hak && !$camera_url) {
  660. //判断是否是mine配置文件的矿区
  661. $mine_res = DB::table('mine_list')->where('id',$parent_id)->get();
  662. //天地伟业
  663. if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine'))){
  664. $result = CameraServices::getRtspTianDi($camera_id,$parent_id);
  665. //宁煤集团
  666. }elseif(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine_hls'))){
  667. $result = CameraServices::getHkHls($camera_id,$parent_id);
  668. }
  669. //大华摄像头
  670. elseif($is_hak == 2){
  671. //同步大华视频服务器摄像头
  672. $tdwy = new TdwyController();
  673. $result = $tdwy->dahuaRtsp($camera_id,$parent_id);
  674. }
  675. //信息技术中心测试ws协议
  676. // elseif($mine_res[0]-> slug == 'XinXiJiShuZhongXin'){
  677. // $result = CameraServices::getHkWs($camera_id,$parent_id);
  678. //
  679. // }
  680. elseif($parent_id == '6561'){//洗选执法记录仪hls
  681. $result = CameraServices::getCameraWssUrl($parent_id, $camera_id);
  682. }
  683. elseif($parent_id == '7004'){//鹰骏一矿外网ws
  684. $result = CameraServices::getCameraWsUrl($parent_id, $camera_id);
  685. }
  686. //海康切片逻辑
  687. else{
  688. $result = CameraServices::downloadCameraFiles($parent_id, $camera_id);
  689. }
  690. } else {
  691. //判断硬盘录像机的有没有封面图,有的走easydrawin,没有的走ffmpeg
  692. $cover_picture = CameraList::where('id', $camera_id)->value('cover_picture');
  693. // if(!$cover_picture){
  694. //ffmpeg拉流获取首帧图片
  695. // $result = CameraServices::getCameraUrlByFfmpeg($camera_id);
  696. // }else{
  697. // $result = CameraServices::getCameraUrlByCameraId($camera_id);
  698. // $result = CameraServices::getRtspYingPan($camera_id);
  699. //硬盘录像机切片测试
  700. $result = CameraServices::getRtspQiePian($camera_id);
  701. // }
  702. }
  703. return self::successResponse($result);
  704. }
  705. public function getCamerasLanUrl()
  706. {
  707. $parent_id = Input::get('parent_id', '');
  708. $camera_id = Input::get('camera_id', '');
  709. if (!$parent_id || !$camera_id) {
  710. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  711. }
  712. //判断摄像头来源是否为内网服务器
  713. $camera_source = CameraList::where('id', $camera_id)->value('camera_source');
  714. if ($camera_source == CameraEnum::CAMERA_SOURCE_3) {
  715. $result = CameraServices::getIntranetCameraUrl($camera_id);
  716. return self::successResponse($result);
  717. }
  718. //判断是否使用海康视频服务器
  719. $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
  720. //判断是否生成摄像头请求链接
  721. $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
  722. if ($is_hak && !$camera_url) {
  723. //判断是否是mine配置文件的矿区
  724. $mine_res = DB::table('mine_list')->where('id',$parent_id)->get();
  725. //天地伟业
  726. if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine'))){
  727. $result = CameraServices::getRtspTianDi($camera_id,$parent_id);
  728. //宁煤集团
  729. }elseif(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine_hls'))){
  730. $result = CameraServices::getHkHls($camera_id,$parent_id);
  731. }else{
  732. $result = CameraServices::getLanCameraUrl($parent_id, $camera_id);
  733. }
  734. } else {
  735. //判断硬盘录像机的有没有封面图,有的走easydrawin,没有的走ffmpeg
  736. $cover_picture = CameraList::where('id', $camera_id)->value('cover_picture');
  737. // if(!$cover_picture){
  738. //ffmpeg拉流获取首帧图片
  739. // $result = CameraServices::getCameraUrlByFfmpeg($camera_id);
  740. // }else{
  741. $result = CameraServices::getCameraUrlByCameraId($camera_id);
  742. // }
  743. }
  744. return self::successResponse($result);
  745. }
  746. //获取海康rtsp流
  747. public function getHikRtsp(){
  748. $parent_id = Input::get('parent_id', '');
  749. $camera_id = Input::get('camera_id', '');
  750. if (!$parent_id || !$camera_id) {
  751. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  752. }
  753. //判断是否使用海康视频服务器
  754. $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
  755. //判断是否生成摄像头请求链接
  756. $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
  757. if ($is_hak == 1 && !$camera_url) {
  758. $result = CameraServices::getHkRtsp($camera_id,$parent_id);
  759. return self::successResponse($result);
  760. }else{
  761. return self::errorResponse(ApiEnum::HK_REQUEST_FAIL);
  762. }
  763. }
  764. //获取海康rtmp流
  765. public function getHikRtmp(){
  766. $parent_id = Input::get('parent_id', '');
  767. $camera_id = Input::get('camera_id', '');
  768. if (!$parent_id || !$camera_id) {
  769. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  770. }
  771. //判断是否使用海康视频服务器
  772. $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
  773. //判断是否生成摄像头请求链接
  774. $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
  775. if ($is_hak == 1 && !$camera_url) {
  776. $result = CameraServices::getHkRtmp($camera_id,$parent_id);
  777. return self::successResponse($result);
  778. }else{
  779. return self::errorResponse(ApiEnum::HK_REQUEST_FAIL);
  780. }
  781. }
  782. //海康摄像头easy_drawin方式获取url
  783. public function getCamerasRtsp()
  784. {
  785. $parent_id = Input::get('parent_id', '');
  786. $camera_id = Input::get('camera_id', '');
  787. if (!$parent_id || !$camera_id) {
  788. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  789. }
  790. //判断摄像头来源是否为内网服务器
  791. $camera_source = CameraList::where('id', $camera_id)->value('camera_source');
  792. if ($camera_source == CameraEnum::CAMERA_SOURCE_3) {
  793. $result = CameraServices::getIntranetCameraUrl($camera_id);
  794. return self::successResponse($result);
  795. }
  796. //判断是否使用海康视频服务器
  797. $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
  798. //判断是否生成摄像头请求链接
  799. $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
  800. if ($is_hak && !$camera_url) {
  801. //判断是否是mine配置文件的矿区
  802. $mine_res = DB::table('mine_list')->where('id',$parent_id)->get();
  803. if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine'))){
  804. //天地伟业使用easy_drawin获取rtsp
  805. $result = CameraServices::getRtspTianDi($camera_id,$parent_id);
  806. }else{
  807. //海康使用easy_drawin获取rtsp
  808. $result = CameraServices::getRtspHaiKang($camera_id, $parent_id);
  809. }
  810. } else {
  811. //硬盘录像机使用easy_drawin获取rtsp
  812. $result = CameraServices::getRtspYingPan($camera_id);
  813. }
  814. return self::successResponse($result);
  815. }
  816. /**
  817. * 作者: qiuzijian
  818. * 注释: 停止摄像头推流
  819. * @return \App\Http\Controllers\Api\JsonResponse
  820. */
  821. public function stopCamerasStream()
  822. {
  823. $camera_id = Input::get('camera_id', '');
  824. $result = CameraServices::stopCameraStream();
  825. return self::successResponse($result);
  826. }
  827. //回放列表
  828. public function getPlaybackList(){
  829. $camera_id = Input::get('camera_id', '');
  830. $result['status'] = true;
  831. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  832. if (!$camera_id) {
  833. $result['status'] = false;
  834. $result['msg'] = ApiEnum::STATUS_CODE_EMPTY;
  835. return $result;
  836. }
  837. $query = CameraList::where('id', $camera_id)->first();
  838. if (!$query) {
  839. $result['status'] = false;
  840. $result['msg'] = ApiEnum::NO_CAMERA_URL;
  841. return $result;
  842. }
  843. if($query->playback == 0){
  844. $result['status'] = false;
  845. $result['msg'] = ApiEnum::NO_SUPORT_PLAYBACK;
  846. return $result;
  847. }
  848. $playback = DB::table('playback')->where('camera_id',$query->id)->where('deleted_at',null)->get();
  849. if(count($playback)>0){
  850. for($i=0;$i<count($playback);$i++){
  851. $result['data'][$i]['title'] = $playback[$i]->title;
  852. $result['data'][$i]['start_time'] = $playback[$i]->start_time;
  853. $result['data'][$i]['end_time'] = $playback[$i]->end_time;
  854. $result['data'][$i]['camera_id'] = $playback[$i]->camera_id;
  855. }
  856. }else{
  857. $result['data'] = null;
  858. }
  859. return $result;
  860. }
  861. //回放URL
  862. public function getPlaybackUrl(){
  863. $time['start_time'] = explode(' ',Input::get('start_time', ''))[1];
  864. $time['end_time'] = explode(' ',Input::get('end_time', ''))[1];
  865. $camera_id = Input::get('camera_id', '');
  866. $start_time = Input::get('start_time', '');
  867. $end_time = Input::get('end_time', '');
  868. $result['status'] = true;
  869. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  870. if (!$camera_id || !$start_time || !$end_time) {
  871. $result['status'] = false;
  872. $result['msg'] = ApiEnum::STATUS_CODE_EMPTY;
  873. return $result;
  874. }
  875. $query = CameraList::where('id', $camera_id)->first();
  876. if (!$query) {
  877. $result['status'] = false;
  878. $result['msg'] = ApiEnum::NO_CAMERA_URL;
  879. return $result;
  880. }
  881. if($query->playback == 0){
  882. $result['status'] = false;
  883. $result['msg'] = ApiEnum::NO_SUPORT_PLAYBACK;
  884. return $result;
  885. }
  886. $degree = MineList::where('id', $query->mine_id)->value('degree');
  887. $degree = explode('|', $degree)[0];
  888. $mine_res = DB::table('mine_list')->where('id',$degree)->get();
  889. //判断摄像头是否是洗选中心的时间+34分钟
  890. if($mine_res[0]->slug == 'XiXuanZhongXin'){
  891. $start_time = date('Y-m-d H:i:s',strtotime($start_time.'+34 minutes'));
  892. $end_time = date('Y-m-d H:i:s',strtotime($end_time.'+34 minutes'));
  893. }
  894. $str = '.000+';
  895. $start_time = date('c', strtotime($start_time));//2022-07-14T08:00:00.000+08:00
  896. $start_time = explode('+',$start_time);
  897. $start_time = $start_time[0].$str.$start_time[1];
  898. $end_time = date('c', strtotime($end_time));
  899. $end_time = explode('+',$end_time);
  900. $end_time = $end_time[0].$str.$end_time[1];
  901. //判断是否在配置文件里,在的不用走ffmpeg
  902. if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('playback'))){
  903. $result = CameraServices::getPlaybackRtsp($camera_id,$start_time,$end_time);
  904. return self::successResponse($result);
  905. }else{
  906. $result = CameraServices::getPlaybackRtmp($camera_id,$start_time,$end_time,$time);
  907. return self::successResponse($result);
  908. }
  909. }
  910. //easydrawin回放URL
  911. public function getPlaybackUrlByEasy(){
  912. $time['start_time'] = explode(' ',Input::get('start_time', ''))[1];
  913. $time['end_time'] = explode(' ',Input::get('end_time', ''))[1];
  914. $camera_id = Input::get('camera_id', '');
  915. $start_time = Input::get('start_time', '');
  916. $end_time = Input::get('end_time', '');
  917. $result['status'] = true;
  918. $result['msg'] = ApiEnum::RETURN_SUCCESS;
  919. if (!$camera_id || !$start_time || !$end_time) {
  920. $result['status'] = false;
  921. $result['msg'] = ApiEnum::STATUS_CODE_EMPTY;
  922. return $result;
  923. }
  924. $query = CameraList::where('id', $camera_id)->first();
  925. if (!$query) {
  926. $result['status'] = false;
  927. $result['msg'] = ApiEnum::NO_CAMERA_URL;
  928. return $result;
  929. }
  930. if($query->playback == 0){
  931. $result['status'] = false;
  932. $result['msg'] = ApiEnum::NO_SUPORT_PLAYBACK;
  933. return $result;
  934. }
  935. $degree = MineList::where('id', $query->mine_id)->value('degree');
  936. $degree = explode('|', $degree)[0];
  937. $mine_res = DB::table('mine_list')->where('id',$degree)->get();
  938. //判断摄像头是否是洗选中心的时间+34分钟
  939. if($mine_res[0]->slug == 'XiXuanZhongXin'){
  940. $start_time = date('Y-m-d H:i:s',strtotime($start_time.'+34 minutes'));
  941. $end_time = date('Y-m-d H:i:s',strtotime($end_time.'+34 minutes'));
  942. }
  943. $str = '.000+';
  944. $start_time = date('c', strtotime($start_time));//2022-07-14T08:00:00.000+08:00
  945. $start_time = explode('+',$start_time);
  946. $start_time = $start_time[0].$str.$start_time[1];
  947. $end_time = date('c', strtotime($end_time));
  948. $end_time = explode('+',$end_time);
  949. $end_time = $end_time[0].$str.$end_time[1];
  950. //判断是否在配置文件里,在的不用走ffmpeg
  951. if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('playback'))){
  952. $result = CameraServices::getPlaybackRtsp($camera_id,$start_time,$end_time);
  953. return self::successResponse($result);
  954. }else{
  955. $result = CameraServices::getPlaybackByEasy($camera_id,$start_time,$end_time,$time);
  956. return self::successResponse($result);
  957. }
  958. }
  959. /**
  960. * 作者: qiuzijian
  961. * 注释: 获取编码设备信息
  962. * @return \App\Http\Controllers\Api\JsonResponse
  963. */
  964. public function getTranscodeInfo()
  965. {
  966. $parent_id = Input::get('parent_id', '');
  967. if (!$parent_id) {
  968. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  969. }
  970. $result = CameraServices::getHaiKangTransCode($parent_id);
  971. return self::successResponse($result);
  972. }
  973. /**
  974. * 作者: qiuzijian
  975. * 注释: 获取大南湖摄像头列表
  976. * @return \App\Http\Controllers\Api\JsonResponse
  977. */
  978. public function getSouthLakeCamera()
  979. {
  980. $result = CameraServices::getLeChangeCamera();
  981. return self::successResponse($result);
  982. }
  983. public function pictureBase64(){
  984. $base64 = Input::get('base64', '');
  985. $camera_id = Input::get('camera_id', '');
  986. if (!$base64 || !$camera_id) {
  987. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  988. }
  989. $data['base64'] = $base64;
  990. DB::table('camera_list')->where('id',$camera_id)->update($data);
  991. return self::successResponse();
  992. }
  993. public function test(){
  994. // header("Access-Control-Allow-Origin: *");
  995. $data = DB::table('goods')->get();
  996. return $data;
  997. }
  998. public function testadd(){
  999. // header("Access-Control-Allow-Origin: *");
  1000. $res['good_name'] = Input::get('good_name', '');
  1001. $res['good_url'] = 'images/1.jpg';
  1002. $res['good_count'] = Input::get('good_count', '');
  1003. $res['good_price'] = Input::get('good_price', '');
  1004. $res['good_state'] = Input::get('good_state', '');
  1005. DB::table('goods')->insert($res);
  1006. return true;
  1007. }
  1008. public function testdel(){
  1009. // header("Access-Control-Allow-Origin: *");
  1010. DB::table('goods')->where('id',Input::get('id',''))->delete();
  1011. return true;
  1012. }
  1013. public function testupdate(){
  1014. // header("Access-Control-Allow-Origin: *");
  1015. $res['good_name'] = Input::get('good_name', '');
  1016. $res['good_url'] = 'images/1.jpg';
  1017. $res['good_count'] = Input::get('good_count', '');
  1018. $res['good_price'] = Input::get('good_price', '');
  1019. $res['good_state'] = Input::get('good_state', '');
  1020. DB::table('goods')->where('id',Input::get('id',''))->update($res);
  1021. return true;
  1022. }
  1023. //值班信息
  1024. public function dutyInformation(){
  1025. $today = date('Y-m-d');
  1026. $tomorrow = date("Y-m-d",strtotime("+1 day"));
  1027. $result['today_zzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$today."' and type = 'zzb'");
  1028. $result['today_fzzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$today."' and type = 'fz'");
  1029. $result['tomorrow_zzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$tomorrow."' and type = 'zzb'");
  1030. $result['tomorrow_fzzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$tomorrow."' and type = 'fz'");
  1031. return self::successResponse($result);
  1032. }
  1033. //分类列表
  1034. public function typeList(){
  1035. $result = $result = DB::connection('etl_zaoquan')->select("select type from news_column_list group by type");
  1036. if(count($result) > 0){
  1037. for($i=0;$i<count($result);$i++){
  1038. if($result[$i]->type=="mkxw"){
  1039. unset($result[$i]);
  1040. $newObject = ['type' => 'mkxw','name'=>'煤矿新闻'];
  1041. array_unshift($result, $newObject);
  1042. }
  1043. if($result[$i]->type == 'aqsc'){
  1044. $result[$i]->name = '安全生产';
  1045. }
  1046. if($result[$i]->type == 'mkxw'){
  1047. $result[$i]->name = '煤矿新闻';
  1048. }
  1049. if($result[$i]->type == 'zwbg'){
  1050. $result[$i]->name = '政务办公';
  1051. }
  1052. if($result[$i]->type == 'djgz'){
  1053. $result[$i]->name = '党建工作';
  1054. }
  1055. if($result[$i]->type == 'qygl'){
  1056. $result[$i]->name = '企业管理';
  1057. }
  1058. if($result[$i]->type == 'jdgl'){
  1059. $result[$i]->name = '机电管理';
  1060. }
  1061. if($result[$i]->type == 'scjsgl'){
  1062. $result[$i]->name = '生产技术管理';
  1063. }
  1064. if($result[$i]->type == 'jjjc'){
  1065. $result[$i]->name = '纪检监察';
  1066. }
  1067. if($result[$i]->type == 'zhzl'){
  1068. $result[$i]->name = '综合治理';
  1069. }
  1070. if($result[$i]->type == 'jypx'){
  1071. $result[$i]->name = '教育培训';
  1072. }
  1073. if($result[$i]->type == 'kwgk'){
  1074. $result[$i]->name = '矿务公开';
  1075. }
  1076. }
  1077. }
  1078. return self::successResponse($result);
  1079. }
  1080. //文章列表
  1081. public function articleList(Request $request){
  1082. $params = $request->all();
  1083. if (!isset($params['page_size'])) {
  1084. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1085. }
  1086. if (!isset($params['page_num'])) {
  1087. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1088. }
  1089. if (!isset($params['type'])) {
  1090. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1091. }
  1092. $offset = $params['page_size'] * ($params['page_num'] - 1);
  1093. $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);
  1094. $pattern = '/<img(.*?)src=["\'](.*?)["\'](.*?)>/i';//图片
  1095. $pattern2 = '/href="([^"]+)"/';//文件
  1096. if(count($result) > 0){
  1097. for($i=0;$i<count($result);$i++){
  1098. //替换title_image
  1099. $old_title_image = $result[$i]->title_image;
  1100. $old_title_image_array = explode('/',$old_title_image);
  1101. $old_img_path = $old_title_image_array[count($old_title_image_array)-1];
  1102. $new_img_path_list = DB::connection('etl_zaoquan')->select("select * from news_img_list where img_name ='".$old_img_path."'");
  1103. if(count($new_img_path_list) > 0){
  1104. $result[$i]->main_img = $new_img_path_list[0]->new_name;
  1105. }
  1106. unset($result[$i]->title_image);
  1107. $result[$i]->created_at = $result[$i]->create_time;
  1108. unset($result[$i]->create_time);
  1109. //替换text的图片
  1110. preg_match_all($pattern, $result[$i]->text, $matches);
  1111. foreach ($matches[2] as $index => $oldSrc) {
  1112. $news_img_list = DB::connection('etl_zaoquan')->select("select * from news_img_list where img_name ='".basename($oldSrc)."'");
  1113. if(count($news_img_list) > 0){
  1114. $newSrc = $news_img_list[0]->new_name;
  1115. $result[$i]->text = str_replace($oldSrc, $newSrc, $result[$i]->text);
  1116. }
  1117. }
  1118. //替换text的文件
  1119. preg_match_all($pattern2, $result[$i]->text, $matches2);
  1120. foreach ($matches2[1] as $index => $oldSrc) {
  1121. $news_file_list = DB::connection('etl_zaoquan')->select("select * from news_img_list where img_name ='".basename($oldSrc)."'");
  1122. if(count($news_file_list) > 0){
  1123. $newSrc = $news_file_list[0]->new_name;
  1124. $result[$i]->text = str_replace($oldSrc, $newSrc, $result[$i]->text);
  1125. }
  1126. }
  1127. }
  1128. }
  1129. return self::successResponse($result);
  1130. }
  1131. //文章图片上传至阿里云
  1132. public function ossUrl(Request $request){
  1133. $params = $request->all();
  1134. if (!isset($params['url'])) {
  1135. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1136. }
  1137. $result = $this->downloadFile($params['url']);
  1138. return self::successResponse($result);
  1139. }
  1140. //下载文件
  1141. public function downloadFile($file_path)
  1142. {
  1143. $rename = mt_rand(1111111,9999999);
  1144. if (!$file_path) {
  1145. return false;
  1146. }
  1147. set_time_limit(0);
  1148. $ch = curl_init($file_path);
  1149. curl_setopt($ch, CURLOPT_HEADER, 0);
  1150. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1151. curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
  1152. $rawdata = curl_exec ($ch);
  1153. curl_close ($ch);
  1154. $houzhui = explode('.',$file_path);
  1155. $houzhui = '.'.$houzhui[count($houzhui)-1];
  1156. // 使用中文文件名需要转码
  1157. $fp = fopen(public_path() . '/filedownload/' . $rename.$houzhui, 'w');
  1158. fwrite($fp, $rawdata);
  1159. fclose($fp);
  1160. $file_name = $rename;
  1161. //上传文件
  1162. $file_oss_path = $this->uploadFile($file_name,$houzhui);
  1163. return $file_oss_path;
  1164. }
  1165. //上传文件
  1166. public function uploadFile($file_name,$houzhui)
  1167. {
  1168. try{
  1169. $oss = new OssClient(
  1170. Config::get('filesystems.disks.oss_view.access_key'),
  1171. Config::get('filesystems.disks.oss_view.secret_key'),
  1172. Config::get('filesystems.disks.oss_view.endpoint')
  1173. );
  1174. $file_path = public_path() . '/filedownload/' . $file_name.$houzhui;
  1175. $res = $oss->uploadFile(Config::get('filesystems.disks.oss_view.bucket'), $file_name.$houzhui, $file_path);
  1176. } catch(\OssException $e) {
  1177. printf(__FUNCTION__ . ": FAILED\n");
  1178. printf($e->getMessage() . "\n");
  1179. return;
  1180. }
  1181. if (isset($res['info']['url']) && $res['info']['url']) {
  1182. unlink($file_path);
  1183. return urldecode($res['info']['url']);
  1184. } else {
  1185. return false;
  1186. }
  1187. }
  1188. //摄像头访问记录入库
  1189. public function cameraRecordInsert(Request $request){
  1190. $params = $request->all();
  1191. // $opcDB = DB::connection('anning');
  1192. // $dbResult = $opcDB->select('select * from uf_dwj_spjkymfw where ymid = 6224');
  1193. if(isset($params['staff_num']) && isset($params['name']) && isset($params['department']) && isset($params['post']) && isset($params['camera_id']) && isset($params['start_time'])){
  1194. $camera = DB::table('camera_list')->where('id',$params['camera_id'])->get();
  1195. $mine = DB::table('mine_list')->where('id',$camera[0]->mine_id)->get();
  1196. $degree = explode('|',$mine[0]->degree);
  1197. $unit = DB::table('mine_list')->where('id',$degree[0])->get();
  1198. $data['staff_num'] = $params['staff_num'];
  1199. $data['name'] = $params['name'];
  1200. $data['department'] = $params['department'];
  1201. $data['post'] = $params['post'];
  1202. $data['mine_id'] = $camera[0]->mine_id;
  1203. $data['camera_id'] = $params['camera_id'];
  1204. $data['camera_name'] = $camera[0]->camera_name;
  1205. $data['unit_name'] = $unit[0]->title;
  1206. if(isset($params['base64']) && $params['base64'] != null && $params['base64'] != ''){
  1207. $data['base64'] = $params['base64'];
  1208. }
  1209. $data['start_time'] = date('Y-m-d').' '.$params['start_time'];
  1210. // $data['start_time'] = date('Y-m-d').' '.$params['end_time'];
  1211. $data['created_at'] = date('Y-m-d H:i:s');
  1212. $data['updated_at'] = date('Y-m-d H:i:s');
  1213. DB::table('camera_record')->insert($data);
  1214. }
  1215. }
  1216. //摄像头访问记录列表
  1217. public function cameraRecordList(Request $request){
  1218. $params = $request->all();
  1219. if (!isset($params['camera_id'])) {
  1220. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1221. }
  1222. $camera_record = DB::table('camera_record')->where('camera_id',$params['camera_id'])->where('deleted_at',null)->orderBy('created_at','desc')->limit(20)->get();
  1223. return self::successResponse($camera_record);
  1224. }
  1225. //摄像头下拉列表
  1226. public function cameraSelect(Request $request){
  1227. $result = '<select style="width:99%;" class="form-control" name="camera"><option value="0">-选择摄像头-</option>';
  1228. $mine_list = DB::table('mine_list')->where('parent_id',6356)->where('id','!=',6492)->where('deleted_at',null)->get();
  1229. if(count($mine_list) > 0){
  1230. for($i=0;$i<count($mine_list);$i++){
  1231. $camera_list = DB::table('camera_list')->where('mine_id',$mine_list[$i]->id)->where('is_show',1)->where('deleted_at',null)->get();
  1232. if(count($camera_list) > 0){
  1233. $result = $result . '<optgroup label="' . $mine_list[$i]->title . '">';
  1234. for($j=0;$j<count($camera_list);$j++){
  1235. $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.'</option>';
  1236. }
  1237. $result = $result . '</optgroup>';
  1238. }
  1239. }
  1240. }
  1241. $result = $result . '</select>';
  1242. return json_encode($result);
  1243. }
  1244. //移动摄像头下拉列表
  1245. public function moveCameraSelect(Request $request){
  1246. $mine_id = 6492;
  1247. $camera = DB::table('camera_list')->where('mine_id',$mine_id)->where('deleted_at',null)->get();
  1248. $result = [];
  1249. if(count($camera) > 0){
  1250. for($i=0;$i<count($camera);$i++){
  1251. $result[$i] = [
  1252. 'name' => $camera[$i]->camera_name,
  1253. 'value' => $camera[$i]->id.'|'.$mine_id.'|'.$camera[$i]->camera_name.'|'.$camera[$i]->camera_type
  1254. ];
  1255. }
  1256. }
  1257. return json_encode($result);
  1258. }
  1259. //执法记录仪下拉列表
  1260. public function zhifaCameraSelect(Request $request){
  1261. $mine_id = 6561;
  1262. $mine_list = DB::table('mine_list')->where('parent_id',$mine_id)->where('show',1)->where('deleted_at',null)->pluck('id');
  1263. $camera_list = DB::table('camera_list')->whereIn('mine_id',$mine_list)->where('is_show',1)->where('camera_status',1)->where('deleted_at',null)->get();
  1264. $result = [];
  1265. if(count($camera_list) > 0){
  1266. for($i=0;$i<count($camera_list);$i++){
  1267. $result[$i] = [
  1268. 'name' => $camera_list[$i]->camera_name,
  1269. 'value' => $camera_list[$i]->id.'|'.$mine_id.'|'.$camera_list[$i]->camera_name.'|'.$camera_list[$i]->camera_type
  1270. ];
  1271. }
  1272. }
  1273. return $result;
  1274. }
  1275. //摄像头信息
  1276. public function cameraInfo(Request $request){
  1277. $params = $request->all();
  1278. $camera = DB::table('camera_list')->where('id',$params['camera_id'])->get();
  1279. $result['id'] = $camera[0]->id;
  1280. $result['camera_name'] = $camera[0]->camera_name;
  1281. $result['camera_url'] = $camera[0]->camera_url;
  1282. $result['camera_type'] = $camera[0]->camera_type;
  1283. $result['cover_picture'] = $camera[0]->cover_picture;
  1284. $result['parent_id'] = $camera[0]->mine_id;
  1285. return $result;
  1286. }
  1287. //使用说明
  1288. public function readme(Request $request){
  1289. $params = $request->all();
  1290. $result['coal_washery'] = DB::connection('task_xixuan')->table('xx_coal_washery')->orderBy('id')->get();
  1291. $mine_list = DB::table('mine_list')->where('parent_id',6356)->where('deleted_at',null)->get();
  1292. $result['camera_list'] = [];
  1293. if(count($mine_list) > 0){
  1294. for($i=0;$i<count($mine_list);$i++){
  1295. $camera_list = DB::table('camera_list')->where('mine_id',$mine_list[$i]->id)->where('is_show',1)->where('deleted_at',null)->get();
  1296. if(count($camera_list) > 0){
  1297. $result['camera_list'][$i]['area'] = $mine_list[$i]->title;
  1298. for($j=0;$j<count($camera_list);$j++){
  1299. $result['camera_list'][$i]['camera_list'][$j] = $camera_list[$j]->id.':'.$camera_list[$j]->camera_name;
  1300. }
  1301. }
  1302. }
  1303. }
  1304. return $result;
  1305. }
  1306. //主屏幕
  1307. public function mainHome(Request $request){
  1308. $gao = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', today())->where('risk_level',0)->count();
  1309. $zhong = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', today())->where('risk_level',1)->count();
  1310. $di = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', today())->where('risk_level',2)->count();
  1311. $result = [
  1312. [
  1313. 'number' => $gao,
  1314. 'unit' => '项',
  1315. 'title' => '高风险作业',
  1316. 'color' => '#DA0000'
  1317. ],
  1318. [
  1319. 'number' => $zhong,
  1320. 'unit' => '项',
  1321. 'title' => '中风险作业',
  1322. 'color' => '#FFBA00'
  1323. ],
  1324. [
  1325. 'number' => $di,
  1326. 'unit' => '项',
  1327. 'title' => '低风险作业',
  1328. 'color' => '#2BB200'
  1329. ]
  1330. ];
  1331. return self::successResponse($result);
  1332. }
  1333. //风险作业占比
  1334. public function riskWorkPercent(Request $request){
  1335. $gao = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', today())->where('risk_level',0)->count();
  1336. $zhong = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', today())->where('risk_level',1)->count();
  1337. $di = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', today())->where('risk_level',2)->count();
  1338. $result = [
  1339. [
  1340. 'value' => $gao,
  1341. 'name' => '高风险',
  1342. ],
  1343. [
  1344. 'value' => $zhong,
  1345. 'name' => '中风险',
  1346. ],
  1347. [
  1348. 'value' => $di,
  1349. 'name' => '低风险',
  1350. ]
  1351. ];
  1352. return self::successResponse($result);
  1353. }
  1354. //片区占比
  1355. public function areaPercent(Request $request){
  1356. $area = DB::connection('task_xixuan')->table('xx_area')->get();
  1357. if(count($area) > 0){
  1358. for($i=0;$i<count($area);$i++){
  1359. $coal_washery_id_list = DB::connection('task_xixuan')->table('xx_coal_washery')->where('area_id',$area[$i]->id)->pluck('id');
  1360. $result[$i]['value'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('optdt', today())->count();
  1361. $result[$i]['name'] = $area[$i]->name;
  1362. }
  1363. }
  1364. return self::successResponse($result);
  1365. }
  1366. //地图数据
  1367. public function mapData(Request $request){
  1368. $coal_washery = DB::connection('task_xixuan')->table('xx_coal_washery')->get();
  1369. $coal_list = [
  1370. '灵新洗煤厂'=>'linxing',
  1371. '红柳洗煤厂'=>'hongliu',
  1372. '枣泉洗煤厂'=>'zaoquan',
  1373. '大武口洗煤厂'=>'dawukou',
  1374. '金凤洗煤厂'=>'jinfeng',
  1375. '检修车间'=>'jianxiuchejian',
  1376. '太西洗煤厂'=>'taixi',
  1377. '清水营洗煤厂'=>'qingshuiying',
  1378. '梅花井洗煤厂'=>'meihuajing',
  1379. '石槽村洗煤厂'=>'shicaocun',
  1380. '双马洗煤厂'=>'shuangma',
  1381. '羊场湾洗煤厂'=>'yangchangwan',
  1382. '羊场湾二分区洗煤厂'=>'yangchangwanerfenqu'
  1383. ];
  1384. if(count($coal_washery) > 0){
  1385. for($i=0;$i<count($coal_washery);$i++){
  1386. if(array_key_exists($coal_washery[$i]->name, $coal_list)) {
  1387. $slog = $coal_list[$coal_washery[$i]->name];
  1388. $result[$slog]['title'] = $coal_washery[$i]->name;
  1389. $result[$slog]['id'] = $coal_washery[$i]->id;
  1390. $result[$slog]['data'] = [
  1391. [
  1392. 'name' => '高风险作业',
  1393. '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()
  1394. ],
  1395. [
  1396. 'name' => '中风险作业',
  1397. '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()
  1398. ],
  1399. [
  1400. 'name' => '低风险作业',
  1401. '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()
  1402. ]
  1403. ];
  1404. }
  1405. }
  1406. }
  1407. return self::successResponse($result);
  1408. }
  1409. //时间段作业数
  1410. public function timeWorkCount(Request $request){
  1411. $params = $request->all();
  1412. if(isset($params['start_date']) && isset($params['end_date'])){
  1413. $start_date = $params['start_date'];
  1414. $end_date = $params['end_date'];
  1415. }else{
  1416. $start_date = date('Y-m-d', strtotime(date('Y-m-d') . ' -6 day'));
  1417. $end_date = date('Y-m-d');
  1418. }
  1419. $current_date = $start_date;
  1420. $i = 0;
  1421. $result = [];
  1422. $result['xAxis']['type'] = 'category';
  1423. $result['xAxis']['data'] = [];
  1424. $result['series'] = [
  1425. [
  1426. 'name' => '高风险作业',
  1427. 'type' => 'bar',
  1428. 'stack'=> 'bar_1',
  1429. 'data' => [],
  1430. 'itemStyle' => [
  1431. 'color' => '#DA0000',
  1432. 'borderRadius' => [10,10,10,10]
  1433. ]
  1434. ],
  1435. [
  1436. 'name' => '中风险作业',
  1437. 'type' => 'bar',
  1438. 'stack'=> 'bar_2',
  1439. 'data' => [],
  1440. 'itemStyle' => [
  1441. 'color' => '#FFBA00',
  1442. 'borderRadius' => [10,10,10,10]
  1443. ]
  1444. ],
  1445. [
  1446. 'name' => '低风险作业',
  1447. 'type' => 'bar',
  1448. 'stack'=> 'bar_3',
  1449. 'data' => [],
  1450. 'itemStyle' => [
  1451. 'color' => '#2BB200',
  1452. 'borderRadius' => [10,10,10,10]
  1453. ]
  1454. ]
  1455. ];
  1456. while ($current_date <= $end_date) {
  1457. array_push($result['xAxis']['data'],$current_date);
  1458. array_push($result['series'][0]['data'],DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $current_date)->where('risk_level',0)->count());
  1459. array_push($result['series'][1]['data'],DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $current_date)->where('risk_level',1)->count());
  1460. array_push($result['series'][2]['data'],DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $current_date)->where('risk_level',2)->count());
  1461. $current_date = date('Y-m-d', strtotime($current_date . ' +1 day'));
  1462. $i++;
  1463. }
  1464. return self::successResponse($result);
  1465. }
  1466. //时间段片区统计
  1467. public function timeAreaTotal(Request $request){
  1468. $params = $request->all();
  1469. if (isset($params['area_id'])) {
  1470. $area_id = $params['area_id'];
  1471. }else{
  1472. $area_id = 1;
  1473. }
  1474. if(isset($params['start_date']) && isset($params['end_date'])){
  1475. $start_date = $params['start_date'];
  1476. $end_date = $params['end_date'];
  1477. }else{
  1478. $start_date = date('Y-m-d', strtotime(date('Y-m-d') . ' -6 day'));
  1479. $end_date = date('Y-m-d');
  1480. }
  1481. $coal_washery_id_list = DB::connection('task_xixuan')->table('xx_coal_washery')->where('area_id',$area_id)->pluck('id');
  1482. $result = [];
  1483. $current_date = $start_date;
  1484. $i = 0;
  1485. //当日片区数
  1486. $result['data'] = [
  1487. [
  1488. '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(),
  1489. 'unit' => '项',
  1490. 'title' => '高风险作业',
  1491. 'color' => '#DA0000'
  1492. ],
  1493. [
  1494. '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(),
  1495. 'unit' => '项',
  1496. 'title' => '中风险作业',
  1497. 'color' => '#FFBA00'
  1498. ],
  1499. [
  1500. '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(),
  1501. 'unit' => '项',
  1502. 'title' => '低风险作业',
  1503. 'color' => '#2BB200'
  1504. ]
  1505. ];
  1506. $result['xAxis']['type'] = 'category';
  1507. $result['xAxis']['data'] = [];
  1508. $result['series'] = [
  1509. [
  1510. 'name' => '高风险作业',
  1511. 'type' => 'line',
  1512. 'data' => [],
  1513. 'itemStyle' => [
  1514. 'color' => '#DA0000',
  1515. 'borderRadius' => [10,10,10,10]
  1516. ]
  1517. ],
  1518. [
  1519. 'name' => '中风险作业',
  1520. 'type' => 'line',
  1521. 'data' => [],
  1522. 'itemStyle' => [
  1523. 'color' => '#FFBA00',
  1524. 'borderRadius' => [10,10,10,10]
  1525. ]
  1526. ],
  1527. [
  1528. 'name' => '低风险作业',
  1529. 'type' => 'line',
  1530. 'data' => [],
  1531. 'itemStyle' => [
  1532. 'color' => '#2BB200',
  1533. 'borderRadius' => [10,10,10,10]
  1534. ]
  1535. ]
  1536. ];
  1537. while ($current_date <= $end_date) {
  1538. array_push($result['xAxis']['data'],$current_date);
  1539. 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());
  1540. 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());
  1541. 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());
  1542. $current_date = date('Y-m-d', strtotime($current_date . ' +1 day'));
  1543. $i++;
  1544. }
  1545. return self::successResponse($result);
  1546. }
  1547. //洗煤厂统计
  1548. public function coalWasheryTotal(Request $request){
  1549. $params = $request->all();
  1550. if(isset($params['area_id'])){
  1551. $area = [$params['area_id']];
  1552. }else{
  1553. $area = [1,2];
  1554. }
  1555. $coal_washery = DB::connection('task_xixuan')->table('xx_coal_washery')->whereIn('area_id',$area)->get();
  1556. if(count($coal_washery) > 0){
  1557. for($i=0;$i<count($coal_washery);$i++){
  1558. $result[$i]['unit_name'] = $coal_washery[$i]->name;
  1559. $result[$i]['coal_washery_id'] = $coal_washery[$i]->id;
  1560. $result[$i]['data'] = [
  1561. [
  1562. 'label' => '高',
  1563. '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(),
  1564. 'color' => '#DA0000'
  1565. ],
  1566. [
  1567. 'label' => '中',
  1568. '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(),
  1569. 'color' => '#FFBA00'
  1570. ],
  1571. [
  1572. 'label' => '低',
  1573. '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(),
  1574. 'color' => '#2BB200'
  1575. ],
  1576. ];
  1577. }
  1578. }
  1579. return self::successResponse($result);
  1580. }
  1581. //风险作业列表
  1582. public function riskWorkList(Request $request){
  1583. $params = $request->all();
  1584. if(isset($params['type'])){
  1585. $type = [$params['type']];
  1586. }else{
  1587. $type = [0,1,2];
  1588. }
  1589. $list = [];
  1590. if(isset($params['area_id'])){
  1591. $list = DB::connection('task_xixuan')->table('xx_coal_washery')->where('area_id',$params['area_id'])->pluck('id');
  1592. }
  1593. if(isset($params['coal_washery_id'])){
  1594. $list = [$params['coal_washery_id']];
  1595. }
  1596. $coal_washery_list = DB::connection('task_xixuan')->table('xx_coal_washery')->get();
  1597. if(count($coal_washery_list) > 0){
  1598. for($i=0;$i<count($coal_washery_list);$i++){
  1599. $result['unit_list'][$i]['text'] = $coal_washery_list[$i]->name;
  1600. $result['unit_list'][$i]['value'] = $coal_washery_list[$i]->name;
  1601. }
  1602. }
  1603. $risk = DB::connection('task_xixuan')->table('xx_risk_assignment');
  1604. $risk = $risk->select('xx_risk_assignment.*','xx_coal_washery.name as coal_washery');
  1605. $risk = $risk->leftJoin('xx_coal_washery','xx_coal_washery.id','=','xx_risk_assignment.coal_washery_id');
  1606. if(count($list) > 0){
  1607. $risk = $risk->whereIn('coal_washery_id',$list);
  1608. }
  1609. $risk = $risk->whereDate('xx_risk_assignment.optdt', today());
  1610. if(isset($params['id'])){
  1611. $risk = $risk->where('xx_coal_washery.id',$params['id']);
  1612. }
  1613. $risk = $risk->whereIn('risk_level',$type)->get();
  1614. $risk_level = ['高风险','中风险','低风险'];
  1615. $risk_type = ['高处坠落','起重伤害','触电','火灾','机械伤害','中毒和窒息','物体打击','淹溺','灼烫','受限空间','坍塌','锅炉爆炸','其他爆炸','其他伤害'];
  1616. $result['data'] = [];
  1617. if(count($risk) > 0){
  1618. for($i=0;$i<count($risk);$i++){
  1619. $result['data'][$i]['id'] = $risk[$i]->id;
  1620. $result['data'][$i]['unit_name'] = $risk[$i]->coal_washery;
  1621. $result['data'][$i]['place'] = $risk[$i]->work_location;
  1622. $result['data'][$i]['content'] = $risk[$i]->risk_name;
  1623. $result['data'][$i]['work_people'] = $risk[$i]->work_people;
  1624. $result['data'][$i]['work_num'] = $risk[$i]->work_num;
  1625. $result['data'][$i]['risk_level'] = $risk_level[$risk[$i]->risk_level];
  1626. if($risk[$i]->risk_type != null){
  1627. $result['data'][$i]['risk_type'] = $risk_type[$risk[$i]->risk_type];
  1628. }else{
  1629. $result['data'][$i]['risk_type'] = '无';
  1630. }
  1631. $result['data'][$i]['coal_washery'] = $risk[$i]->coal_washery;
  1632. }
  1633. }
  1634. return self::successResponse($result);
  1635. }
  1636. //风险作业详情
  1637. public function riskWorkDetail(Request $request){
  1638. $params = $request->all();
  1639. if (!isset($params['id'])) {
  1640. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1641. }
  1642. $risk_type = ['高处坠落','起重伤害','触电','火灾','机械伤害','中毒和窒息','物体打击','淹溺','灼烫','受限空间','坍塌','锅炉爆炸','其他爆炸','其他伤害'];
  1643. $risk_level = ['高风险','中风险','低风险'];
  1644. $type = '';
  1645. $camera_name = '无';
  1646. $result['camera']['camera_id'] = '';
  1647. $result['camera']['parent_id'] = '';
  1648. $move_type = '';
  1649. $move_camera_name = '无';
  1650. $result['move_camera']['camera_id'] = '';
  1651. $result['move_camera']['parent_id'] = '';
  1652. $zhifa_type = '';
  1653. $zhifa_camera_name = '无';
  1654. $result['zhifa_camera']['camera_id'] = '';
  1655. $result['zhifa_camera']['parent_id'] = '';
  1656. $risk = DB::connection('task_xixuan')->table('xx_risk_assignment')
  1657. ->select('xx_risk_assignment.*','xx_coal_washery.name as coal_washery')
  1658. ->leftJoin('xx_coal_washery','xx_coal_washery.id','=','xx_risk_assignment.coal_washery_id')
  1659. ->where('xx_risk_assignment.id',$params['id'])->get();
  1660. if(count($risk) > 0){
  1661. $camera_info = explode('|',$risk[0]->camera_id);
  1662. if(count($camera_info) > 1){
  1663. $camera_name = $camera_info[2];
  1664. $is_hak = MineListExt::where('mine_id', $camera_info[1])->value('is_hak');
  1665. if($is_hak == 2){
  1666. $type = 'rtsp';
  1667. }else{
  1668. $type = 'm3u8';
  1669. }
  1670. }
  1671. $move_camera_info = explode('|',$risk[0]->move_camera_id);
  1672. if(count($move_camera_info) > 1){
  1673. $move_camera_name = $move_camera_info[2];
  1674. $is_hak = MineListExt::where('mine_id', $move_camera_info[1])->value('is_hak');
  1675. if($is_hak == 2){
  1676. $move_type = 'rtsp';
  1677. }else{
  1678. $move_type = 'm3u8';
  1679. }
  1680. }
  1681. $zhifa_camera_info = explode('|',$risk[0]->zhifa_camera_id);
  1682. if(count($zhifa_camera_info) > 1){
  1683. $zhifa_camera_name = $zhifa_camera_info[2];
  1684. $is_hak = MineListExt::where('mine_id', $zhifa_camera_info[1])->value('is_hak');
  1685. if($is_hak == 2){
  1686. $zhifa_type = 'rtsp';
  1687. }else{
  1688. $zhifa_type = 'm3u8';
  1689. }
  1690. }
  1691. if($risk[0]->risk_type != '' && $risk[0]->risk_type !=null){
  1692. $risk_type_value = $risk_type[$risk[0]->risk_type];
  1693. }else{
  1694. $risk_type_value = '无';
  1695. }
  1696. $result['detail'] = [
  1697. [
  1698. 'label' => '所属单位:',
  1699. 'value' => $risk[0]->unit
  1700. ],
  1701. [
  1702. 'label' => '区队名称:',
  1703. 'value' => $risk[0]->coal_washery
  1704. ],
  1705. [
  1706. 'label' => '班次:',
  1707. 'value' => $risk[0]->classes
  1708. ],
  1709. [
  1710. 'label' => '作业人数:',
  1711. 'value' => $risk[0]->work_num
  1712. ],
  1713. [
  1714. 'label' => '风险等级:',
  1715. 'value' => $risk_level[$risk[0]->risk_level]
  1716. ],
  1717. [
  1718. 'label' => '风险类型:',
  1719. 'value' => $risk_type_value
  1720. ],
  1721. [
  1722. 'label' => '作业内容:',
  1723. 'value' => $risk[0]->risk_name
  1724. ],
  1725. [
  1726. 'label' => '作业地点:',
  1727. 'value' => $risk[0]->work_location
  1728. ],
  1729. [
  1730. 'label' => '现场负责人:',
  1731. 'value' => $risk[0]->work_people
  1732. ],
  1733. [
  1734. 'label' => '进展情况:',
  1735. 'value' => $risk[0]->describe
  1736. ],
  1737. [
  1738. 'label' => '固定摄像头:',
  1739. 'value' => $camera_name
  1740. ],
  1741. [
  1742. 'label' => '移动摄像头:',
  1743. 'value' => $move_camera_name
  1744. ],
  1745. [
  1746. 'label' => '执法记录仪:',
  1747. 'value' => $zhifa_camera_name
  1748. ],
  1749. ];
  1750. $camera_id = explode('|',$risk[0]->camera_id);
  1751. if(count($camera_id) > 1){
  1752. $result['camera']['camera_id'] = $camera_id[0];
  1753. $result['camera']['parent_id'] = $camera_id[1];
  1754. }
  1755. $result['camera']['camera_type'] = $type;
  1756. $move_camera_id = explode('|',$risk[0]->move_camera_id);
  1757. if(count($move_camera_id) > 1){
  1758. $result['move_camera']['camera_id'] = $move_camera_id[0];
  1759. $result['move_camera']['parent_id'] = $move_camera_id[1];
  1760. }
  1761. $result['move_camera']['camera_type'] = $move_type;
  1762. $zhifa_camera_id = explode('|',$risk[0]->zhifa_camera_id);
  1763. if(count($zhifa_camera_id) > 1){
  1764. $result['zhifa_camera']['camera_id'] = $zhifa_camera_id[0];
  1765. $result['zhifa_camera']['parent_id'] = $zhifa_camera_id[1];
  1766. }
  1767. $result['zhifa_camera']['camera_type'] = $zhifa_type;
  1768. }
  1769. return self::successResponse($result);
  1770. }
  1771. //首頁信息
  1772. public function taskHome(Request $request){
  1773. $risk_type = ['高处坠落','起重伤害','触电','火灾','机械伤害','中毒和窒息','物体打击','淹溺','灼烫','受限空间','坍塌','锅炉爆炸','其他爆炸','其他伤害'];
  1774. $risk_level = ['高风险','中风险','低风险'];
  1775. //高风险作业
  1776. $gaofengxian = DB::connection('task_xixuan')->table('xx_risk_assignment')
  1777. ->select('xx_risk_assignment.*','xx_coal_washery.name as coal_washery')
  1778. ->leftJoin('xx_coal_washery','xx_coal_washery.id','=','xx_risk_assignment.coal_washery_id')
  1779. ->whereDate('xx_risk_assignment.optdt', today())
  1780. ->where('risk_level',0)->get();
  1781. if(count($gaofengxian) > 0){
  1782. for($i=0;$i<count($gaofengxian);$i++){
  1783. if($gaofengxian[$i]->risk_type == ''){
  1784. $gaofengxian[$i]->risk_type_name = '无';
  1785. }else{
  1786. $gaofengxian[$i]->risk_type_name = $risk_type[$gaofengxian[$i]->risk_type];
  1787. }
  1788. $camera_info = explode('|',$gaofengxian[$i]->camera_id);
  1789. $gaofengxian[$i]->camera_type = CameraEnum::CAMERA_TYPE_EXCHANGE[$camera_info[3]];
  1790. $gaofengxian[$i]->risk_level_name = $risk_level[$gaofengxian[$i]->risk_level];
  1791. }
  1792. }
  1793. $result['gao_count'] = count($gaofengxian);
  1794. $result['gao'] = $gaofengxian;
  1795. //中风险作业
  1796. $zhongfengxian = DB::connection('task_xixuan')->table('xx_risk_assignment')
  1797. ->select('xx_risk_assignment.*','xx_coal_washery.name as coal_washery')
  1798. ->leftJoin('xx_coal_washery','xx_coal_washery.id','=','xx_risk_assignment.coal_washery_id')
  1799. ->whereDate('xx_risk_assignment.optdt', today())
  1800. ->where('risk_level',1)->get();
  1801. if(count($zhongfengxian) > 0){
  1802. for($i=0;$i<count($zhongfengxian);$i++){
  1803. if($zhongfengxian[$i]->risk_type == ''){
  1804. $zhongfengxian[$i]->risk_type_name = '无';
  1805. }else{
  1806. $zhongfengxian[$i]->risk_type_name = $risk_type[$zhongfengxian[$i]->risk_type];
  1807. }
  1808. $camera_info = explode('|',$zhongfengxian[$i]->camera_id);
  1809. $zhongfengxian[$i]->camera_type = CameraEnum::CAMERA_TYPE_EXCHANGE[$camera_info[3]];
  1810. $zhongfengxian[$i]->risk_level_name = $risk_level[$zhongfengxian[$i]->risk_level];
  1811. }
  1812. }
  1813. $result['zhong_count'] = count($zhongfengxian);
  1814. $result['zhong'] = $zhongfengxian;
  1815. //低风险作业
  1816. $difengxian = DB::connection('task_xixuan')->table('xx_risk_assignment')
  1817. ->select('xx_risk_assignment.*','xx_coal_washery.name as coal_washery')
  1818. ->leftJoin('xx_coal_washery','xx_coal_washery.id','=','xx_risk_assignment.coal_washery_id')
  1819. ->whereDate('xx_risk_assignment.optdt', today())
  1820. ->where('risk_level',2)->get();
  1821. if(count($difengxian) > 0){
  1822. for($i=0;$i<count($difengxian);$i++){
  1823. if($difengxian[$i]->risk_type == ''){
  1824. $difengxian[$i]->risk_type_name = '无';
  1825. }else{
  1826. $difengxian[$i]->risk_type_name = $risk_type[$difengxian[$i]->risk_type];
  1827. }
  1828. $camera_info = explode('|',$difengxian[$i]->camera_id);
  1829. $difengxian[$i]->camera_type = CameraEnum::CAMERA_TYPE_EXCHANGE[$camera_info[3]];
  1830. $difengxian[$i]->risk_level_name = $risk_level[$difengxian[$i]->risk_level];
  1831. }
  1832. }
  1833. $result['di_count'] = count($difengxian);
  1834. $result['di'] = $difengxian;
  1835. //片区作业数
  1836. $area = DB::connection('task_xixuan')->table('xx_area')->get();
  1837. $result['area_count'] = [];
  1838. if(count($area) > 0){
  1839. for($i=0;$i<count($area);$i++){
  1840. $result['area_count'][$i]['name'] = $area[$i]->name;
  1841. $coal_washery_id_list = DB::connection('task_xixuan')->table('xx_coal_washery')->where('area_id',$area[$i]->id)->pluck('id');
  1842. $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();
  1843. }
  1844. }
  1845. //洗煤厂作业
  1846. $coal_washery = DB::connection('task_xixuan')->table('xx_coal_washery')->get();
  1847. $result['coal_washery_work_count'] = [];
  1848. if(count($coal_washery) > 0){
  1849. for($i=0;$i<count($coal_washery);$i++){
  1850. $result['coal_washery_work_count'][$i]['name'] = $coal_washery[$i]->name;
  1851. $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();
  1852. $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();
  1853. $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();
  1854. }
  1855. }
  1856. //7天作业数
  1857. $result['seven_work_count'] = [];
  1858. for($i=0;$i<7;$i++){
  1859. $day = date('Y-m-d', strtotime('-'.$i.' day'));
  1860. $result['seven_work_count'][$i]['date'] = $day;
  1861. $result['seven_work_count'][$i]['gao'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $day)->where('risk_level',0)->count();
  1862. $result['seven_work_count'][$i]['zhong'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $day)->where('risk_level',1)->count();
  1863. $result['seven_work_count'][$i]['di'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $day)->where('risk_level',2)->count();
  1864. }
  1865. //7天片区作业数
  1866. $result['seven_area_work_count'] = [];
  1867. if(count($area) > 0){
  1868. for($i=0;$i<count($area);$i++){
  1869. $result['seven_area_work_count'][$i]['name'] = $area[$i]->name;
  1870. $result['seven_area_work_count'][$i]['area_id'] = $area[$i]->id;
  1871. for($j=0;$j<7;$j++){
  1872. $day = date('Y-m-d', strtotime('-'.$j.' day'));
  1873. $result['seven_area_work_count'][$i]['work'][$j]['date'] = $day;
  1874. $coal_washery_id_list = DB::connection('task_xixuan')->table('xx_coal_washery')->where('area_id',$area[$i]->id)->pluck('id');
  1875. $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();
  1876. $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();
  1877. $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();
  1878. }
  1879. }
  1880. }
  1881. return self::successResponse($result);
  1882. }
  1883. //首页作业查询
  1884. public function workSearch(Request $request){
  1885. $params = $request->all();
  1886. if (!isset($params['start_date'])) {
  1887. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1888. }
  1889. if (!isset($params['end_date'])) {
  1890. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1891. }
  1892. $result = [];
  1893. $start_date = $params['start_date'];
  1894. $end_date = $params['end_date'];
  1895. $current_date = $start_date;
  1896. $i = 0;
  1897. while ($current_date <= $end_date) {
  1898. $result[$i]['date'] = $current_date;
  1899. $result[$i]['gao'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $current_date)->where('risk_level',0)->count();
  1900. $result[$i]['zhong'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $current_date)->where('risk_level',1)->count();
  1901. $result[$i]['di'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $current_date)->where('risk_level',2)->count();
  1902. $current_date = date('Y-m-d', strtotime($current_date . ' +1 day'));
  1903. $i++;
  1904. }
  1905. return self::successResponse($result);
  1906. }
  1907. //首页片区作业查询
  1908. public function areaWorkSearch(Request $request){
  1909. $params = $request->all();
  1910. if (!isset($params['start_date'])) {
  1911. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1912. }
  1913. if (!isset($params['end_date'])) {
  1914. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1915. }
  1916. if (!isset($params['area_id'])) {
  1917. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  1918. }
  1919. $coal_washery_id_list = DB::connection('task_xixuan')->table('xx_coal_washery')->where('area_id',$params['area_id'])->pluck('id');
  1920. $result = [];
  1921. $start_date = $params['start_date'];
  1922. $end_date = $params['end_date'];
  1923. $current_date = $start_date;
  1924. $i = 0;
  1925. while ($current_date <= $end_date) {
  1926. $result[$i]['date'] = $current_date;
  1927. $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();
  1928. $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();
  1929. $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();
  1930. $current_date = date('Y-m-d', strtotime($current_date . ' +1 day'));
  1931. $i++;
  1932. }
  1933. return self::successResponse($result);
  1934. }
  1935. //主屏幕
  1936. public function mainHomeV2(Request $request){
  1937. $gao = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('risk_level',0)->where('is_delete',0)->count();
  1938. $zhong = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('risk_level',1)->where('is_delete',0)->count();
  1939. $di = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('risk_level',2)->where('is_delete',0)->count();
  1940. $result = [
  1941. [
  1942. 'number' => $gao,
  1943. 'unit' => '项',
  1944. 'title' => '高风险作业',
  1945. 'color' => '#DA0000'
  1946. ],
  1947. [
  1948. 'number' => $zhong,
  1949. 'unit' => '项',
  1950. 'title' => '中风险作业',
  1951. 'color' => '#FFBA00'
  1952. ],
  1953. [
  1954. 'number' => $di,
  1955. 'unit' => '项',
  1956. 'title' => '低风险作业',
  1957. 'color' => '#2BB200'
  1958. ]
  1959. ];
  1960. return self::successResponse($result);
  1961. }
  1962. //风险作业占比
  1963. public function riskWorkPercentV2(Request $request){
  1964. $gao = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('risk_level',0)->where('is_delete',0)->count();
  1965. $zhong = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('risk_level',1)->where('is_delete',0)->count();
  1966. $di = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('risk_level',2)->where('is_delete',0)->count();
  1967. $result = [
  1968. [
  1969. 'value' => $gao,
  1970. 'name' => '高风险',
  1971. ],
  1972. [
  1973. 'value' => $zhong,
  1974. 'name' => '中风险',
  1975. ],
  1976. [
  1977. 'value' => $di,
  1978. 'name' => '低风险',
  1979. ]
  1980. ];
  1981. return self::successResponse($result);
  1982. }
  1983. //片区占比
  1984. public function areaPercentV2(Request $request){
  1985. $area = DB::connection('mysql_fwe10')->table('uf_xx_area')->where('is_delete',0)->get();
  1986. if(count($area) > 0){
  1987. for($i=0;$i<count($area);$i++){
  1988. $coal_washery_id_list = DB::connection('mysql_fwe10')->table('uf_xx_coal_washery')->where('area_id',$area[$i]->ID)->where('is_delete',0)->pluck('id');
  1989. $result[$i]['value'] = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('is_delete',0)->count();
  1990. $result[$i]['name'] = $area[$i]->title;
  1991. }
  1992. }
  1993. return self::successResponse($result);
  1994. }
  1995. //地图数据
  1996. public function mapDataV2(Request $request){
  1997. $coal_washery = DB::connection('mysql_fwe10')->table('uf_xx_coal_washery')->where('is_delete',0)->get();
  1998. $coal_list = [
  1999. '灵新洗煤厂'=>'linxing',
  2000. '红柳洗煤厂'=>'hongliu',
  2001. '枣泉洗煤厂'=>'zaoquan',
  2002. // '大武口洗煤厂'=>'dawukou',
  2003. '金凤洗煤厂'=>'jinfeng',
  2004. '金能洗煤厂'=>'jinneng',
  2005. '检修一车间'=>'jianxiuyichejian',
  2006. '检修二车间'=>'jianxiuerchejian',
  2007. // '检修三车间'=>'jianxiusanchejian',
  2008. // '太西洗煤厂'=>'taixi',
  2009. '清水营洗煤厂'=>'qingshuiying',
  2010. '梅花井洗煤厂'=>'meihuajing',
  2011. '石槽村洗煤厂'=>'shicaocun',
  2012. '双马洗煤厂'=>'shuangma',
  2013. '羊场湾洗煤厂'=>'yangchangwan',
  2014. '羊二洗煤厂'=>'yanger'
  2015. ];
  2016. $result['other_data'] = [];
  2017. if(count($coal_washery) > 0){
  2018. for($i=0;$i<count($coal_washery);$i++){
  2019. if(array_key_exists($coal_washery[$i]->title, $coal_list)) {
  2020. $slog = $coal_list[$coal_washery[$i]->title];
  2021. $result['map_data'][$slog]['title'] = $coal_washery[$i]->title;
  2022. $result['map_data'][$slog]['id'] = $coal_washery[$i]->ID;
  2023. $result['map_data'][$slog]['data'] = [
  2024. [
  2025. 'name' => '高风险作业',
  2026. 'value'=> DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->ID)->where('risk_level',0)->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('is_delete',0)->count()
  2027. ],
  2028. [
  2029. 'name' => '中风险作业',
  2030. 'value'=> DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->ID)->where('risk_level',1)->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('is_delete',0)->count()
  2031. ],
  2032. [
  2033. 'name' => '低风险作业',
  2034. 'value'=> DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->ID)->where('risk_level',2)->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('is_delete',0)->count()
  2035. ]
  2036. ];
  2037. }else{
  2038. array_push($result['other_data'],[
  2039. 'title'=> $coal_washery[$i]->title,
  2040. 'id' => $coal_washery[$i]->ID,
  2041. 'gao' => DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->ID)->where('risk_level',0)->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('is_delete',0)->count(),
  2042. 'zhong'=> DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->ID)->where('risk_level',1)->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('is_delete',0)->count(),
  2043. 'di' => DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->ID)->where('risk_level',2)->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('is_delete',0)->count()
  2044. ]);
  2045. }
  2046. }
  2047. }
  2048. return self::successResponse($result);
  2049. }
  2050. //时间段作业数
  2051. public function timeWorkCountV2(Request $request){
  2052. $params = $request->all();
  2053. if(isset($params['start_date']) && isset($params['end_date'])){
  2054. $start_date = $params['start_date'];
  2055. $end_date = $params['end_date'];
  2056. }else{
  2057. $start_date = date('Y-m-d', strtotime(date('Y-m-d') . ' -6 day'));
  2058. $end_date = date('Y-m-d');
  2059. }
  2060. $current_date = $start_date;
  2061. $i = 0;
  2062. $result = [];
  2063. $result['xAxis']['type'] = 'category';
  2064. $result['xAxis']['data'] = [];
  2065. $result['series'] = [
  2066. [
  2067. 'name' => '高风险作业',
  2068. 'type' => 'bar',
  2069. 'stack'=> 'bar_1',
  2070. 'data' => [],
  2071. 'itemStyle' => [
  2072. 'color' => '#DA0000',
  2073. 'borderRadius' => [10,10,10,10]
  2074. ]
  2075. ],
  2076. [
  2077. 'name' => '中风险作业',
  2078. 'type' => 'bar',
  2079. 'stack'=> 'bar_2',
  2080. 'data' => [],
  2081. 'itemStyle' => [
  2082. 'color' => '#FFBA00',
  2083. 'borderRadius' => [10,10,10,10]
  2084. ]
  2085. ],
  2086. [
  2087. 'name' => '低风险作业',
  2088. 'type' => 'bar',
  2089. 'stack'=> 'bar_3',
  2090. 'data' => [],
  2091. 'itemStyle' => [
  2092. 'color' => '#2BB200',
  2093. 'borderRadius' => [10,10,10,10]
  2094. ]
  2095. ]
  2096. ];
  2097. while ($current_date <= $end_date) {
  2098. array_push($result['xAxis']['data'],$current_date);
  2099. array_push($result['series'][0]['data'],DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereDate('create_time', $current_date)->where('risk_level',0)->where('is_delete',0)->count());
  2100. array_push($result['series'][1]['data'],DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereDate('create_time', $current_date)->where('risk_level',1)->where('is_delete',0)->count());
  2101. array_push($result['series'][2]['data'],DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereDate('create_time', $current_date)->where('risk_level',2)->where('is_delete',0)->count());
  2102. $current_date = date('Y-m-d', strtotime($current_date . ' +1 day'));
  2103. $i++;
  2104. }
  2105. return self::successResponse($result);
  2106. }
  2107. //时间段片区统计
  2108. public function timeAreaTotalV2(Request $request){
  2109. $params = $request->all();
  2110. if (isset($params['area_id'])) {
  2111. if($params['area_id'] == 1){//宁东
  2112. $area_id = '1055262869143609349';
  2113. }elseif($params['area_id'] == 2){//太西
  2114. $area_id = '1055262899082551297';
  2115. }else{
  2116. $area_id = $params['area_id'];
  2117. }
  2118. }else{
  2119. $area_id = DB::connection('mysql_fwe10')->table('uf_xx_area')->where('is_delete',0)->first()->ID;
  2120. }
  2121. if(isset($params['start_date']) && isset($params['end_date'])){
  2122. $start_date = $params['start_date'];
  2123. $end_date = $params['end_date'];
  2124. }else{
  2125. $start_date = date('Y-m-d', strtotime(date('Y-m-d') . ' -6 day'));
  2126. $end_date = date('Y-m-d');
  2127. }
  2128. $coal_washery_id_list = DB::connection('mysql_fwe10')->table('uf_xx_coal_washery')->where('area_id',$area_id)->where('is_delete',0)->pluck('id');
  2129. $result = [];
  2130. $current_date = $start_date;
  2131. $i = 0;
  2132. //当日片区数
  2133. $result['data'] = [
  2134. [
  2135. 'number' => DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('risk_level',0)->where('is_delete',0)->count(),
  2136. 'unit' => '项',
  2137. 'title' => '高风险作业',
  2138. 'color' => '#DA0000'
  2139. ],
  2140. [
  2141. 'number' => DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('risk_level',1)->where('is_delete',0)->count(),
  2142. 'unit' => '项',
  2143. 'title' => '中风险作业',
  2144. 'color' => '#FFBA00'
  2145. ],
  2146. [
  2147. 'number' => DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('risk_level',2)->where('is_delete',0)->count(),
  2148. 'unit' => '项',
  2149. 'title' => '低风险作业',
  2150. 'color' => '#2BB200'
  2151. ]
  2152. ];
  2153. $result['xAxis']['type'] = 'category';
  2154. $result['xAxis']['data'] = [];
  2155. $result['series'] = [
  2156. [
  2157. 'name' => '高风险作业',
  2158. 'type' => 'line',
  2159. 'data' => [],
  2160. 'itemStyle' => [
  2161. 'color' => '#DA0000',
  2162. 'borderRadius' => [10,10,10,10]
  2163. ]
  2164. ],
  2165. [
  2166. 'name' => '中风险作业',
  2167. 'type' => 'line',
  2168. 'data' => [],
  2169. 'itemStyle' => [
  2170. 'color' => '#FFBA00',
  2171. 'borderRadius' => [10,10,10,10]
  2172. ]
  2173. ],
  2174. [
  2175. 'name' => '低风险作业',
  2176. 'type' => 'line',
  2177. 'data' => [],
  2178. 'itemStyle' => [
  2179. 'color' => '#2BB200',
  2180. 'borderRadius' => [10,10,10,10]
  2181. ]
  2182. ]
  2183. ];
  2184. while ($current_date <= $end_date) {
  2185. array_push($result['xAxis']['data'],$current_date);
  2186. array_push($result['series'][0]['data'],DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('create_time', $current_date)->where('risk_level',0)->where('is_delete',0)->count());
  2187. array_push($result['series'][1]['data'],DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('create_time', $current_date)->where('risk_level',1)->where('is_delete',0)->count());
  2188. array_push($result['series'][2]['data'],DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('create_time', $current_date)->where('risk_level',2)->where('is_delete',0)->count());
  2189. $current_date = date('Y-m-d', strtotime($current_date . ' +1 day'));
  2190. $i++;
  2191. }
  2192. return self::successResponse($result);
  2193. }
  2194. //洗煤厂统计
  2195. public function coalWasheryTotalV2(Request $request){
  2196. $params = $request->all();
  2197. if(isset($params['area_id'])){
  2198. $area = [$params['area_id']];
  2199. }else{
  2200. $area = DB::connection('mysql_fwe10')->table('uf_xx_area')->where('is_delete',0)->pluck('id');
  2201. }
  2202. $coal_washery = DB::connection('mysql_fwe10')->table('uf_xx_coal_washery')->whereIn('area_id',$area)->where('is_delete',0)->get();
  2203. if(count($coal_washery) > 0){
  2204. for($i=0;$i<count($coal_washery);$i++){
  2205. $result[$i]['unit_name'] = $coal_washery[$i]->title;
  2206. $result[$i]['coal_washery_id'] = $coal_washery[$i]->ID;
  2207. $result[$i]['data'] = [
  2208. [
  2209. 'label' => '高',
  2210. 'value' => DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->ID)->where('risk_level',0)->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('is_delete',0)->count(),
  2211. 'color' => '#DA0000'
  2212. ],
  2213. [
  2214. 'label' => '中',
  2215. 'value' => DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->ID)->where('risk_level',1)->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('is_delete',0)->count(),
  2216. 'color' => '#FFBA00'
  2217. ],
  2218. [
  2219. 'label' => '低',
  2220. 'value' => DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->ID)->where('risk_level',2)->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('is_delete',0)->count(),
  2221. 'color' => '#2BB200'
  2222. ],
  2223. ];
  2224. }
  2225. }
  2226. return self::successResponse($result);
  2227. }
  2228. //风险作业列表
  2229. public function riskWorkListV2(Request $request){
  2230. $params = $request->all();
  2231. if(isset($params['type'])){
  2232. $type = [$params['type']];
  2233. }else{
  2234. $type = [0,1,2];
  2235. }
  2236. $list = [];
  2237. if(isset($params['area_id'])){
  2238. $list = DB::connection('mysql_fwe10')->table('uf_xx_coal_washery')->where('area_id',$params['area_id'])->where('is_delete',0)->pluck('id');
  2239. }
  2240. if(isset($params['coal_washery_id'])){
  2241. $list = [$params['coal_washery_id']];
  2242. }
  2243. $coal_washery_list = DB::connection('mysql_fwe10')->table('uf_xx_coal_washery')->where('is_delete',0)->get();
  2244. if(count($coal_washery_list) > 0){
  2245. for($i=0;$i<count($coal_washery_list);$i++){
  2246. $result['unit_list'][$i]['text'] = $coal_washery_list[$i]->title;
  2247. $result['unit_list'][$i]['value'] = $coal_washery_list[$i]->title;
  2248. }
  2249. }
  2250. $risk = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment');
  2251. $risk = $risk->select('uf_xx_risk_assignment.*','uf_xx_coal_washery.title as coal_washery');
  2252. $risk = $risk->leftJoin('uf_xx_coal_washery','uf_xx_coal_washery.id','=','uf_xx_risk_assignment.coal_washery_id');
  2253. if(count($list) > 0){
  2254. $risk = $risk->whereIn('coal_washery_id',$list);
  2255. }
  2256. $risk = $risk->whereDate('uf_xx_risk_assignment.create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('uf_xx_risk_assignment.is_delete',0);
  2257. if(isset($params['id'])){
  2258. $risk = $risk->where('uf_xx_coal_washery.id',$params['id']);
  2259. }
  2260. $risk = $risk->whereIn('risk_level',$type)->orderBy('uf_xx_risk_assignment.risk_level')->get();
  2261. $risk_level = ['高风险','中风险','低风险'];
  2262. $risk_type = ['高处坠落','起重伤害','触电','火灾','机械伤害','中毒和窒息','物体打击','淹溺','灼烫','受限空间','坍塌','锅炉爆炸','其他爆炸','其他伤害'];
  2263. $result['data'] = [];
  2264. if(count($risk) > 0){
  2265. for($i=0;$i<count($risk);$i++){
  2266. $result['data'][$i]['id'] = $risk[$i]->ID;
  2267. $result['data'][$i]['unit_name'] = $risk[$i]->coal_washery;
  2268. $result['data'][$i]['place'] = $risk[$i]->risk_location;
  2269. $result['data'][$i]['content'] = $risk[$i]->risk_name;
  2270. $result['data'][$i]['work_people'] = $risk[$i]->work_people;
  2271. $result['data'][$i]['work_num'] = $risk[$i]->work_num;
  2272. $result['data'][$i]['risk_level'] = $risk_level[$risk[$i]->risk_level];
  2273. if($risk[$i]->risk_type != null){
  2274. $result['data'][$i]['risk_type'] = $risk_type[$risk[$i]->risk_type];
  2275. }else{
  2276. $result['data'][$i]['risk_type'] = '无';
  2277. }
  2278. $result['data'][$i]['coal_washery'] = $risk[$i]->coal_washery;
  2279. }
  2280. }
  2281. return self::successResponse($result);
  2282. }
  2283. //风险作业详情
  2284. public function riskWorkDetailV2(Request $request){
  2285. $params = $request->all();
  2286. if (!isset($params['id'])) {
  2287. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  2288. }
  2289. $result['camera'] = [];
  2290. $result['move_camera'] = [];
  2291. $result['zhifa_camera'] = [];
  2292. $risk_type = ['高处坠落','起重伤害','触电','火灾','机械伤害','中毒和窒息','物体打击','淹溺','灼烫','受限空间','坍塌','锅炉爆炸','其他爆炸','其他伤害'];
  2293. $risk_level = ['高风险','中风险','低风险'];
  2294. $classes = ['早班','中班','夜班'];
  2295. $risk = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')
  2296. ->select('uf_xx_risk_assignment.*','uf_xx_coal_washery.title as coal_washery')
  2297. ->leftJoin('uf_xx_coal_washery','uf_xx_coal_washery.id','=','uf_xx_risk_assignment.coal_washery_id')
  2298. ->where('uf_xx_risk_assignment.id',$params['id'])->where('uf_xx_risk_assignment.is_delete',0)->get();
  2299. if(count($risk) > 0){
  2300. $camera_info = explode(',',$risk[0]->camera);
  2301. if($camera_info[0] != ''){
  2302. for($i=0;$i<count($camera_info);$i++){
  2303. preg_match('/^(.*)\((\d+)\)$/', $camera_info[$i], $matches);
  2304. if (isset($matches[1]) && isset($matches[2])) {
  2305. $result['camera'][$i]['camera_name'] = $matches[1];
  2306. $result['camera'][$i]['camera_id'] = $matches[2];
  2307. $result['camera'][$i]['parent_id'] = DB::table('camera_list')->where('id',$matches[2])->pluck('mine_id')[0];
  2308. }
  2309. }
  2310. }
  2311. $move_camera_info = explode(',',$risk[0]->move_camera);
  2312. if($move_camera_info[0] != ''){
  2313. for($i=0;$i<count($move_camera_info);$i++){
  2314. preg_match('/^(.*)\((\d+)\)$/', $move_camera_info[$i], $matches2);
  2315. if (isset($matches2[1]) && isset($matches2[2])) {
  2316. $result['move_camera'][$i]['camera_name'] = $matches2[1];
  2317. $result['move_camera'][$i]['camera_id'] = $matches2[2];
  2318. $result['move_camera'][$i]['parent_id'] = 6492;
  2319. }
  2320. }
  2321. }
  2322. $zhifa_camera_info = explode(',',$risk[0]->zhifa_camera);
  2323. if($zhifa_camera_info[0] != ''){
  2324. for($i=0;$i<count($zhifa_camera_info);$i++){
  2325. preg_match('/^(.*)\((\d+)\)$/', $zhifa_camera_info[$i], $matches3);
  2326. if (isset($matches3[1]) && isset($matches3[2])) {
  2327. $result['zhifa_camera'][$i]['camera_name'] = $matches3[1];
  2328. $result['zhifa_camera'][$i]['camera_id'] = $matches3[2];
  2329. $result['zhifa_camera'][$i]['parent_id'] = 6561;
  2330. $result['zhifa_camera'][$i]['color'] = 4;
  2331. }
  2332. }
  2333. }
  2334. $zhifa_people_list = DB::connection('mysql_fwe10')->table('uf_xx_zhifa')->where('is_delete',0)->get();
  2335. if(count($zhifa_people_list) > 0){
  2336. for($i=0;$i<count($zhifa_people_list);$i++){
  2337. $pos = strpos($risk[0]->work_people, $zhifa_people_list[$i]->xm);
  2338. if ($pos !== false) {
  2339. $camera = DB::table('camera_list')->where('camera_name',$zhifa_people_list[$i]->camera_name)->where('deleted_at',null)->get();
  2340. if(count($camera) > 0){
  2341. if($zhifa_people_list[$i]->color === null){
  2342. $zhifa_people_list[$i]->color = 4;
  2343. }
  2344. array_push($result['zhifa_camera'],[
  2345. 'camera_name'=> $zhifa_people_list[$i]->camera_name,
  2346. 'camera_id' => $camera[0]->id,
  2347. 'parent_id' => 6561,
  2348. 'color' => $zhifa_people_list[$i]->color
  2349. ]);
  2350. }
  2351. }
  2352. }
  2353. }
  2354. //去掉数组重复部分
  2355. $unique_cameras = [];
  2356. foreach ($result['zhifa_camera'] as $camera) {
  2357. $unique_cameras[$camera['camera_id']] = $camera;
  2358. }
  2359. $result['zhifa_camera'] = array_values($unique_cameras);
  2360. if($risk[0]->risk_type != '' && $risk[0]->risk_type !=null){
  2361. $risk_type_value = $risk_type[$risk[0]->risk_type];
  2362. }else{
  2363. $risk_type_value = '无';
  2364. }
  2365. $result['detail'] = [
  2366. [
  2367. 'label' => '所属单位:',
  2368. 'value' => $risk[0]->unit
  2369. ],
  2370. [
  2371. 'label' => '区队名称:',
  2372. 'value' => $risk[0]->coal_washery
  2373. ],
  2374. [
  2375. 'label' => '班次:',
  2376. 'value' => $classes[$risk[0]->classes]
  2377. ],
  2378. [
  2379. 'label' => '作业人数:',
  2380. 'value' => $risk[0]->work_num
  2381. ],
  2382. [
  2383. 'label' => '风险等级:',
  2384. 'value' => $risk_level[$risk[0]->risk_level]
  2385. ],
  2386. [
  2387. 'label' => '风险类型:',
  2388. 'value' => $risk_type_value
  2389. ],
  2390. [
  2391. 'label' => '作业内容:',
  2392. 'value' => $risk[0]->risk_name
  2393. ],
  2394. [
  2395. 'label' => '作业地点:',
  2396. 'value' => $risk[0]->risk_location
  2397. ],
  2398. [
  2399. 'label' => '现场负责人:',
  2400. 'value' => $risk[0]->work_people
  2401. ],
  2402. [
  2403. 'label' => '进展情况:',
  2404. 'value' => $risk[0]->risk_describe
  2405. ]
  2406. ];
  2407. }
  2408. return self::successResponse($result);
  2409. }
  2410. //首頁信息
  2411. public function taskHomeV2(Request $request){
  2412. $risk_type = ['高处坠落','起重伤害','触电','火灾','机械伤害','中毒和窒息','物体打击','淹溺','灼烫','受限空间','坍塌','锅炉爆炸','其他爆炸','其他伤害'];
  2413. $risk_level = ['高风险','中风险','低风险'];
  2414. //高风险作业
  2415. $gaofengxian = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')
  2416. ->select('uf_xx_risk_assignment.*','uf_xx_coal_washery.name as coal_washery')
  2417. ->leftJoin('uf_xx_coal_washery','uf_xx_coal_washery.id','=','uf_xx_risk_assignment.coal_washery_id')
  2418. ->whereDate('uf_xx_risk_assignment.create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))
  2419. ->where('risk_level',0)->where('uf_xx_risk_assignment.is_delete',0)->get();
  2420. if(count($gaofengxian) > 0){
  2421. for($i=0;$i<count($gaofengxian);$i++){
  2422. if($gaofengxian[$i]->risk_type == ''){
  2423. $gaofengxian[$i]->risk_type_name = '无';
  2424. }else{
  2425. $gaofengxian[$i]->risk_type_name = $risk_type[$gaofengxian[$i]->risk_type];
  2426. }
  2427. $camera_info = explode(',',$gaofengxian[$i]->camera);
  2428. $gaofengxian[$i]->camera_type = '普通摄像头';
  2429. $gaofengxian[$i]->risk_level_name = $risk_level[$gaofengxian[$i]->risk_level];
  2430. }
  2431. }
  2432. $result['gao_count'] = count($gaofengxian);
  2433. $result['gao'] = $gaofengxian;
  2434. //中风险作业
  2435. $zhongfengxian = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')
  2436. ->select('uf_xx_risk_assignment.*','uf_xx_coal_washery.name as coal_washery')
  2437. ->leftJoin('uf_xx_coal_washery','uf_xx_coal_washery.id','=','uf_xx_risk_assignment.coal_washery_id')
  2438. ->whereDate('uf_xx_risk_assignment.create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))
  2439. ->where('risk_level',1)->where('uf_xx_risk_assignment.is_delete',0)->get();
  2440. if(count($zhongfengxian) > 0){
  2441. for($i=0;$i<count($zhongfengxian);$i++){
  2442. if($zhongfengxian[$i]->risk_type == ''){
  2443. $zhongfengxian[$i]->risk_type_name = '无';
  2444. }else{
  2445. $zhongfengxian[$i]->risk_type_name = $risk_type[$zhongfengxian[$i]->risk_type];
  2446. }
  2447. $camera_info = explode(',',$zhongfengxian[$i]->camera);
  2448. $zhongfengxian[$i]->camera_type = '普通摄像头';
  2449. $zhongfengxian[$i]->risk_level_name = $risk_level[$zhongfengxian[$i]->risk_level];
  2450. }
  2451. }
  2452. $result['zhong_count'] = count($zhongfengxian);
  2453. $result['zhong'] = $zhongfengxian;
  2454. //低风险作业
  2455. $difengxian = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')
  2456. ->select('uf_xx_risk_assignment.*','uf_xx_coal_washery.name as coal_washery')
  2457. ->leftJoin('uf_xx_coal_washery','uf_xx_coal_washery.id','=','uf_xx_risk_assignment.coal_washery_id')
  2458. ->whereDate('uf_xx_risk_assignment.create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))
  2459. ->where('risk_level',2)->where('uf_xx_risk_assignment.is_delete',0)->get();
  2460. if(count($difengxian) > 0){
  2461. for($i=0;$i<count($difengxian);$i++){
  2462. if($difengxian[$i]->risk_type == ''){
  2463. $difengxian[$i]->risk_type_name = '无';
  2464. }else{
  2465. $difengxian[$i]->risk_type_name = $risk_type[$difengxian[$i]->risk_type];
  2466. }
  2467. $camera_info = explode(',',$difengxian[$i]->camera);
  2468. $difengxian[$i]->camera_type = '普通摄像头';
  2469. $difengxian[$i]->risk_level_name = $risk_level[$difengxian[$i]->risk_level];
  2470. }
  2471. }
  2472. $result['di_count'] = count($difengxian);
  2473. $result['di'] = $difengxian;
  2474. //片区作业数
  2475. $area = DB::connection('mysql_fwe10')->table('uf_xx_area')->get();
  2476. $result['area_count'] = [];
  2477. if(count($area) > 0){
  2478. for($i=0;$i<count($area);$i++){
  2479. $result['area_count'][$i]['name'] = $area[$i]->title;
  2480. $coal_washery_id_list = DB::connection('mysql_fwe10')->table('uf_xx_coal_washery')->where('area_id',$area[$i]->ID)->pluck('id');
  2481. $result['area_count'][$i]['count'] = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('is_delete',0)->count();
  2482. }
  2483. }
  2484. //洗煤厂作业
  2485. $coal_washery = DB::connection('mysql_fwe10')->table('uf_xx_coal_washery')->where('is_delete',0)->get();
  2486. $result['coal_washery_work_count'] = [];
  2487. if(count($coal_washery) > 0){
  2488. for($i=0;$i<count($coal_washery);$i++){
  2489. $result['coal_washery_work_count'][$i]['name'] = $coal_washery[$i]->title;
  2490. $result['coal_washery_work_count'][$i]['gao'] = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->ID)->where('risk_level',0)->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('is_delete',0)->count();
  2491. $result['coal_washery_work_count'][$i]['zhong'] = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->ID)->where('risk_level',1)->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('is_delete',0)->count();
  2492. $result['coal_washery_work_count'][$i]['di'] = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->where('coal_washery_id',$coal_washery[$i]->ID)->where('risk_level',2)->whereDate('create_time', DB::raw('CURDATE() - INTERVAL 1 DAY'))->where('is_delete',0)->count();
  2493. }
  2494. }
  2495. //7天作业数
  2496. $result['seven_work_count'] = [];
  2497. for($i=0;$i<7;$i++){
  2498. $day = date('Y-m-d', strtotime('-'.$i.' day'));
  2499. $result['seven_work_count'][$i]['date'] = $day;
  2500. $result['seven_work_count'][$i]['gao'] = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereDate('create_time', $day)->where('risk_level',0)->where('is_delete',0)->count();
  2501. $result['seven_work_count'][$i]['zhong'] = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereDate('create_time', $day)->where('risk_level',1)->where('is_delete',0)->count();
  2502. $result['seven_work_count'][$i]['di'] = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereDate('create_time', $day)->where('risk_level',2)->where('is_delete',0)->count();
  2503. }
  2504. //7天片区作业数
  2505. $result['seven_area_work_count'] = [];
  2506. if(count($area) > 0){
  2507. for($i=0;$i<count($area);$i++){
  2508. $result['seven_area_work_count'][$i]['name'] = $area[$i]->title;
  2509. $result['seven_area_work_count'][$i]['area_id'] = $area[$i]->ID;
  2510. for($j=0;$j<7;$j++){
  2511. $day = date('Y-m-d', strtotime('-'.$j.' day'));
  2512. $result['seven_area_work_count'][$i]['work'][$j]['date'] = $day;
  2513. $coal_washery_id_list = DB::connection('mysql_fwe10')->table('uf_xx_coal_washery')->where('area_id',$area[$i]->ID)->where('is_delete',0)->pluck('id');
  2514. $result['seven_area_work_count'][$i]['work'][$j]['gao'] = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('create_time', $day)->where('risk_level',0)->where('is_delete',0)->count();
  2515. $result['seven_area_work_count'][$i]['work'][$j]['zhong'] = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('create_time', $day)->where('risk_level',1)->where('is_delete',0)->count();
  2516. $result['seven_area_work_count'][$i]['work'][$j]['di'] = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('create_time', $day)->where('risk_level',2)->where('is_delete',0)->count();
  2517. }
  2518. }
  2519. }
  2520. return self::successResponse($result);
  2521. }
  2522. //首页作业查询
  2523. public function workSearchV2(Request $request){
  2524. $params = $request->all();
  2525. if (!isset($params['start_date'])) {
  2526. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  2527. }
  2528. if (!isset($params['end_date'])) {
  2529. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  2530. }
  2531. $result = [];
  2532. $start_date = $params['start_date'];
  2533. $end_date = $params['end_date'];
  2534. $current_date = $start_date;
  2535. $i = 0;
  2536. while ($current_date <= $end_date) {
  2537. $result[$i]['date'] = $current_date;
  2538. $result[$i]['gao'] = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereDate('create_time', $current_date)->where('risk_level',0)->where('is_delete',0)->count();
  2539. $result[$i]['zhong'] = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereDate('create_time', $current_date)->where('risk_level',1)->where('is_delete',0)->count();
  2540. $result[$i]['di'] = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereDate('create_time', $current_date)->where('risk_level',2)->where('is_delete',0)->count();
  2541. $current_date = date('Y-m-d', strtotime($current_date . ' +1 day'));
  2542. $i++;
  2543. }
  2544. return self::successResponse($result);
  2545. }
  2546. //首页片区作业查询
  2547. public function areaWorkSearchV2(Request $request){
  2548. $params = $request->all();
  2549. if (!isset($params['start_date'])) {
  2550. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  2551. }
  2552. if (!isset($params['end_date'])) {
  2553. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  2554. }
  2555. if (!isset($params['area_id'])) {
  2556. return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
  2557. }
  2558. $coal_washery_id_list = DB::connection('mysql_fwe10')->table('uf_xx_coal_washery')->where('area_id',$params['area_id'])->where('is_delete',0)->pluck('id');
  2559. $result = [];
  2560. $start_date = $params['start_date'];
  2561. $end_date = $params['end_date'];
  2562. $current_date = $start_date;
  2563. $i = 0;
  2564. while ($current_date <= $end_date) {
  2565. $result[$i]['date'] = $current_date;
  2566. $result[$i]['gao'] = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('create_time', $current_date)->where('risk_level',0)->where('is_delete',0)->count();
  2567. $result[$i]['zhong'] = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('create_time', $current_date)->where('risk_level',1)->where('is_delete',0)->count();
  2568. $result[$i]['di'] = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('create_time', $current_date)->where('risk_level',2)->where('is_delete',0)->count();
  2569. $current_date = date('Y-m-d', strtotime($current_date . ' +1 day'));
  2570. $i++;
  2571. }
  2572. return self::successResponse($result);
  2573. }
  2574. //导出总表
  2575. public function export1(Request $request){
  2576. $params = $request->all();
  2577. $date = $request->query('date', date('Y-m-d'));
  2578. $coal_washery_id = $request->query('coal_washery_id');
  2579. $area_id = $request->query('area_id');
  2580. $classes = ['早班','中班','夜班','早班、中夜、夜班','早班、夜班','早班、中夜'];
  2581. $risk_desc = ['高风险','中风险','低风险'];
  2582. $risk_describe_dict = [0=>"设备日常检修、维护", 1=>"停产检修", 2=>"大中修", 3=>"计划性检修", 4=>"委外施工"];
  2583. // 风险类型
  2584. $risk_type = DB::connection('mysql_fwe10')
  2585. ->table('field_option as t')
  2586. ->where('t.field_id', '1055270106096394246')
  2587. ->where('t.is_delete',0)
  2588. ->where('t.delete_type',0)
  2589. ->get();
  2590. // 如果上边查到的风险类型还有问题的话,就用下边的维护的,不要去查数据库
  2591. $risk_type_dict = ['高处坠落','起重伤害','触电','火灾','机械伤害','中毒和窒息','物体打击','淹溺','灼烫','受限空间','坍塌','锅炉爆炸','其他爆炸','其他伤害'];;
  2592. foreach ($risk_type as $key=>$value) {
  2593. $risk_type_key = $value->value_key;
  2594. $risk_type_name = $value->NAME;
  2595. $risk_type_dict[$risk_type_key] = $risk_type_name;
  2596. }
  2597. if(!empty($area_id)){
  2598. // 风险数据 is_delete = 0 and delete_type = 0 and flow_id is not null
  2599. $risk_list = DB::connection('mysql_fwe10')
  2600. ->table('uf_xx_risk_assignment as t')
  2601. ->select('t.*','t1.shr as coal_shr')
  2602. ->whereDate('t.create_time', $date)
  2603. ->where('t.is_delete',0)
  2604. ->where('t.delete_type',0)
  2605. ->where('t.current_step','结束节点')
  2606. ->whereNotNull('t.flow_id');
  2607. }else{
  2608. // 风险数据 is_delete = 0 and delete_type = 0 and flow_id is not null
  2609. $risk_list = DB::connection('mysql_fwe10')
  2610. ->table('uf_xx_risk_assignment as t')
  2611. ->whereDate('t.create_time', $date)
  2612. ->where('t.is_delete',0)
  2613. ->where('t.delete_type',0)
  2614. ->where('t.current_step','结束节点')
  2615. ->whereNotNull('t.flow_id');
  2616. }
  2617. if (!empty($coal_washery_id)) $risk_list->where('t.coal_washery_id', $coal_washery_id); // 筛选洗煤厂
  2618. if (!empty($area_id)) {
  2619. $risk_list->join('uf_xx_coal_washery as t1','t.coal_washery_id','=','t1.id')
  2620. ->where('t1.is_delete',0)
  2621. ->where('t1.delete_type',0)
  2622. ->join('uf_xx_area as t2','t1.area_id','=','t2.id')
  2623. ->where('t2.is_delete',0)
  2624. ->where('t2.delete_type',0)
  2625. ->where('t2.id', $area_id);
  2626. }
  2627. $risk_list = $risk_list->orderBy('risk_level')->get();
  2628. $str2="春检:";
  2629. // 存放春检数据
  2630. $temp_list=[];
  2631. // 存放其他数据
  2632. $temp_list2=[];
  2633. foreach ($risk_list as $key=>$value){
  2634. if (strstr($value->risk_name, $str2)){
  2635. $temp_list[] = $value;
  2636. }else{
  2637. $temp_list2[] = $value;
  2638. }
  2639. }
  2640. unset($risk_list);
  2641. $risk_list = [];
  2642. foreach ($temp_list2 as $key=>$value){
  2643. $risk_list[] = $value;
  2644. }
  2645. foreach ($temp_list as $key=>$value){
  2646. $risk_list[] = $value;
  2647. }
  2648. // 洗煤厂数据
  2649. $coal_washery_list = DB::connection('mysql_fwe10')->table('uf_xx_coal_washery as t')->where('t.is_delete',0);
  2650. if (!empty($coal_washery_id)) $coal_washery_list->where('t.id', $coal_washery_id); // 筛选洗煤厂
  2651. // 筛选片区
  2652. if (!empty($area_id)) {
  2653. $coal_washery_list->leftJoin('uf_xx_area as t1','t1.id','=','t.area_id')
  2654. ->where('t1.id', $area_id);
  2655. }
  2656. $coal_washery_list = $coal_washery_list->select('t.*')->orderBy('t.sort')->get();
  2657. $coal_washery_dict = [];
  2658. $coal_washery_type_dict = [];
  2659. foreach ($coal_washery_list as $key=>$value) {
  2660. $coal_washery_dict[$value->ID] = $value;
  2661. $coal_washery_type_dict[$value->ID] = $value->obj_type;
  2662. }
  2663. $res = [
  2664. "num" => 0,
  2665. "gao" => 0,
  2666. "zhong" => 0,
  2667. "di" => 0,
  2668. "ziying" => 0,
  2669. "waiwei" => 0,
  2670. "risk_info" => "",
  2671. "ziying_list" => [],
  2672. "waiwei_list" => [],
  2673. "table_list" => [],
  2674. ];
  2675. $risk_zhong_con = [];
  2676. $risk_gao_con = [];
  2677. $coal_washery_risk_list = [];
  2678. // 组织字典
  2679. foreach ($risk_list as $key=>$value) {
  2680. // 获取洗煤厂ID
  2681. $coal_washery_id = $value->coal_washery_id;
  2682. // 风险数量统计
  2683. $risk_level = $value->risk_level; // 风险类型
  2684. $risk_type = $risk_type_dict[$value->risk_type] ?? 2;
  2685. if($risk_level == 0) {
  2686. $res['gao']++;
  2687. if (!isset($risk_gao_con[$risk_type])) {
  2688. $risk_gao_con[$risk_type] = 1;
  2689. } else {
  2690. $risk_gao_con[$risk_type] ++;
  2691. };
  2692. } else if($risk_level == 1) {
  2693. $res['zhong']++;
  2694. if (!isset($risk_zhong_con[$risk_type])) {
  2695. $risk_zhong_con[$risk_type] = 1;
  2696. } else {
  2697. $risk_zhong_con[$risk_type] ++;
  2698. };
  2699. } else {
  2700. $res['di']++;
  2701. }
  2702. // 洗煤厂类型统计(委外、自营)
  2703. $coal_washery_type = $coal_washery_dict[$coal_washery_id]->obj_type ?? "<请检查洗煤厂是否已被删除!>";
  2704. if($coal_washery_type == 0) {
  2705. $res['ziying']++;
  2706. } else if ($coal_washery_type == 1) {
  2707. $res['waiwei']++;
  2708. }
  2709. // 煤矿风险列表
  2710. $coal_washery_risk_list[$coal_washery_id][] = $value;
  2711. }
  2712. $res['num'] = count($risk_list);
  2713. $coal_list = [];
  2714. $index = 0;
  2715. $index_ziying = 0;
  2716. $index_waiwei = 0;
  2717. foreach ($coal_washery_dict as $key => $value) {
  2718. $id = $value->ID;
  2719. if (isset($coal_washery_risk_list[$id])) {
  2720. $index++;
  2721. $people = 0;//计划人数
  2722. $gao = 0;
  2723. $zhong = 0;
  2724. $di = 0;
  2725. $content = '';//工作内容
  2726. $place = '';//作业地点
  2727. $leader = '';//负责人
  2728. $reviewer = [];//审核人
  2729. $coal_washery_risk_info_arr = $coal_washery_risk_list[$id];
  2730. // 如果修改后的代码可以正常运行一段时间,以下注释的代码都可以删除,修改时间2025/1/9
  2731. $risk_index = 0;
  2732. if (isset($coal_washery_type_dict[$id])) {
  2733. $coal_washery_type = $coal_washery_type_dict[$id];
  2734. if ($coal_washery_type == 0) {
  2735. foreach ($coal_washery_risk_info_arr as $k => $v) {
  2736. $people += $v->work_num;
  2737. $risk_info = '';
  2738. if ($v->risk_level == 0) {
  2739. $gao++;
  2740. if($v->risk_type != null) {
  2741. $risk_info = '(' . $risk_desc[$v->risk_level] . ',' . $risk_type_dict[$v->risk_type] . ')';
  2742. }else{
  2743. $risk_info = '('.$risk_desc[$v->risk_level].')';
  2744. }
  2745. } else if ($v->risk_level == 1) {
  2746. $zhong++;
  2747. if($v->risk_type != null){
  2748. $risk_info = '('.$risk_desc[$v->risk_level].','.$risk_type_dict[$v->risk_type].')';
  2749. }else{
  2750. $risk_info = '('.$risk_desc[$v->risk_level].')';
  2751. }
  2752. } else {
  2753. $di++;
  2754. }
  2755. $content .= ++$risk_index.".".$v->risk_name.$risk_info.";\n";
  2756. $place .= $risk_index.".".$v->risk_location.";\n";
  2757. $leader .= $risk_index.".".$v->work_people.";\n";
  2758. if (isset($v->shr) && !empty($v->shr)) {
  2759. $reviewer[] = $v->shr;
  2760. }
  2761. $reviewer = array_unique($reviewer);
  2762. }
  2763. // $line['index'] = ++ $index_ziying;
  2764. // $res["ziying_list"][] = $line;
  2765. } else {
  2766. foreach ($coal_washery_risk_info_arr as $k => $v) {
  2767. $people += $v->work_num;
  2768. $risk_info = '';
  2769. if ($v->risk_level == 0) {
  2770. $gao++;
  2771. if($v->risk_type != null){
  2772. $risk_info = '('.$risk_desc[$v->risk_level].','.$risk_type_dict[$v->risk_type].')';
  2773. }else{
  2774. $risk_info = '('.$risk_desc[$v->risk_level].')';
  2775. }
  2776. // $risk_info = '('.$risk_desc[$v->risk_level].','.$risk_type_dict[$v->risk_type].')';
  2777. } else if ($v->risk_level == 1) {
  2778. $zhong++;
  2779. if($v->risk_type != null){
  2780. $risk_info = '('.$risk_desc[$v->risk_level].','.$risk_type_dict[$v->risk_type].')';
  2781. }else{
  2782. $risk_info = '('.$risk_desc[$v->risk_level].')';
  2783. }
  2784. // $risk_info = '('.$risk_desc[$v->risk_level].','.$risk_type_dict[$v->risk_type].')';
  2785. } else {
  2786. $di++;
  2787. }
  2788. $content .= ++$risk_index.".".$v->risk_name.$risk_info.";\n";
  2789. $place .= $risk_index.".".$v->risk_location.";\n";
  2790. $leader .= $risk_index.".".$v->work_people.";\n";
  2791. if (isset($v->shr) && !empty($v->shr)) {
  2792. $reviewer[] = $v->shr;
  2793. }
  2794. $reviewer = array_unique($reviewer);
  2795. }
  2796. }
  2797. }
  2798. $level_total = '';
  2799. if ($gao > 0) $level_total .= '高风险'.$gao."项\n";
  2800. if ($zhong > 0) $level_total .= '中风险'.$zhong."项\n";
  2801. if ($di > 0) $level_total .= '低风险'.$di.'项';
  2802. $line = [
  2803. 'index' => $index,
  2804. 'unit' => $v->unit,
  2805. 'coal_washery' => $value->title,
  2806. 'classes' => $classes[$v->classes],
  2807. 'work_num' => $people,
  2808. 'level' => $level_total,
  2809. 'content' => $content,
  2810. 'place' => $place,
  2811. 'leader' => $leader,
  2812. 'risk_dexcribe' => $risk_describe_dict[$v->risk_describe],
  2813. 'reviewer' => implode(',', $reviewer),
  2814. 'id' => $value->ID,
  2815. ];
  2816. // $coal_list[] = $line;
  2817. // 自营、外委
  2818. if (isset($coal_washery_type_dict[$id])) {
  2819. $coal_washery_type = $coal_washery_type_dict[$id];
  2820. if ($coal_washery_type == 0) {
  2821. $line['index'] = ++ $index_ziying;
  2822. $res["ziying_list"][] = $line;
  2823. } else {
  2824. $line['index'] = ++ $index_waiwei;
  2825. $res["waiwei_list"][] = $line;
  2826. }
  2827. }
  2828. }
  2829. }
  2830. // $res['table_list'] = $coal_list;
  2831. // foreach($res["ziying_list"] as $key => $value){
  2832. // $content = substr($value["content"], 0, -3);
  2833. // $res["ziying_list"][$key]["content"] =$content;
  2834. // }
  2835. $ziying_people = 0;
  2836. $waiwei_people = 0;
  2837. for ($i = 0; $i < count($res["ziying_list"]); $i++) {
  2838. $content = $res["ziying_list"][$i]['content'];
  2839. // $content = substr($content, 0, -1);
  2840. $content = "\n".$content;
  2841. $res["ziying_list"][$i]['content'] = $content;
  2842. $place = $res["ziying_list"][$i]['place'];
  2843. $place = substr($place, 0, -1);
  2844. $res["ziying_list"][$i]['place'] = $place;
  2845. $leader = $res["ziying_list"][$i]['leader'];
  2846. $leader = substr($leader, 0, -1);
  2847. $res["ziying_list"][$i]['leader'] = $leader;
  2848. $ziying_people = $ziying_people + $res["ziying_list"][$i]['work_num'];
  2849. }
  2850. for ($i = 0; $i < count($res["waiwei_list"]); $i++) {
  2851. $content = $res["waiwei_list"][$i]['content'];
  2852. // $content = substr($content, 0, -1);
  2853. $content = "\n".$content;
  2854. $res["waiwei_list"][$i]['content'] = $content;
  2855. $place = $res["waiwei_list"][$i]['place'];
  2856. $place = substr($place, 0, -1);
  2857. $res["waiwei_list"][$i]['place'] = $place;
  2858. $leader = $res["waiwei_list"][$i]['leader'];
  2859. $leader = substr($leader, 0, -1);
  2860. $res["waiwei_list"][$i]['leader'] = $leader;
  2861. $waiwei_people = $waiwei_people + $res["waiwei_list"][$i]['work_num'];
  2862. }
  2863. if ($area_id == 1055262899082551297){
  2864. $res['people_info'] = "太西片区作业人数:" . ($ziying_people + $waiwei_people) ."人;其中:内部:".$ziying_people."人,外委施工:".$waiwei_people."人";
  2865. } else{
  2866. $res['people_info'] = "作业人数:" . ($ziying_people + $waiwei_people) ."人;其中:内部:".$ziying_people."人,外委施工:".$waiwei_people."人";
  2867. }
  2868. if ($res['gao'] > 0) {
  2869. $risk_gao_info = '(其中:';
  2870. foreach ($risk_gao_con as $key => $value) {
  2871. $risk_gao_info .= $key.$value.'项,';
  2872. }
  2873. $risk_gao_info = substr($risk_gao_info, 0, -3);
  2874. $risk_gao_info .= ');';
  2875. } else {
  2876. $risk_gao_info = ";";
  2877. }
  2878. if ($res['zhong'] > 0) {
  2879. $risk_zhong_info = '(其中:';
  2880. foreach ($risk_zhong_con as $key => $value) {
  2881. $risk_zhong_info .= $key.$value.'项,';
  2882. }
  2883. $risk_zhong_info = substr($risk_zhong_info, 0, -3);
  2884. $risk_zhong_info .= ');';
  2885. } else {
  2886. $risk_zhong_info = ";";
  2887. }
  2888. $res['risk_info'] = "总作业项:".$res['num']."项;高风险:".$res['gao']."项".$risk_gao_info."中风险:".$res['zhong']."项".$risk_zhong_info."低风险:".$res['di']."项。";
  2889. return $res;
  2890. }
  2891. //导出分类表
  2892. public function export2Type(Request $request){
  2893. $params = $request->all();
  2894. $type_list = [];
  2895. $index = 0;
  2896. $nd_gao = 0;
  2897. $nd_zhong = 0;
  2898. $nd_di = 0;
  2899. $tx_gao = 0;
  2900. $tx_zhong = 0;
  2901. $tx_di = 0;
  2902. $risk_type = ['高处坠落','起重伤害','触电','火灾','机械伤害','中毒和窒息','物体打击','淹溺','灼烫','受限空间','坍塌','锅炉爆炸','其他爆炸','其他伤害'];
  2903. if(isset($params['date'])){
  2904. $date = $params['date'];
  2905. }else{
  2906. $date = date('Y-m-d');
  2907. }
  2908. $risk_list = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment as risk')
  2909. ->select('risk.risk_type','risk.risk_level','risk.risk_name','risk.work_num','risk.risk_location','risk.work_people','risk.move_camera','coal.title as coal_title','area.title as area_title','area.id as area_id')
  2910. ->leftJoin('uf_xx_coal_washery as coal','coal.id','=','risk.coal_washery_id')
  2911. ->leftJoin('uf_xx_area as area','area.id','=','coal.area_id')
  2912. ->where('risk.is_delete',0)
  2913. ->where('risk.delete_type',0)
  2914. ->whereDate('risk.fill_date', $date)
  2915. // ->whereIn('risk.risk_level',[0,1])
  2916. ->where('risk.current_step','结束节点')
  2917. ->whereNotNull('risk.flow_id')
  2918. ->orderBy('coal.area_id')
  2919. ->orderBy('risk.risk_level')
  2920. ->get();
  2921. for($i=0;$i<count($risk_type);$i++){
  2922. $count_gao = 0;
  2923. $count_zhong = 0;
  2924. $data = [];
  2925. if(count($risk_list) > 0){
  2926. for($j=0;$j<count($risk_list);$j++){
  2927. if($risk_list[$j]->area_id == '1055262869143609349' && $risk_list[$j]->risk_type == $i){
  2928. if($risk_list[$j]->risk_level == 0){
  2929. $count_gao++;
  2930. $nd_gao++;
  2931. }
  2932. if($risk_list[$j]->risk_level == 1){
  2933. $count_zhong++;
  2934. $nd_zhong++;
  2935. }
  2936. if($risk_list[$j]->risk_level != 2){
  2937. $index++;
  2938. if ($risk_list[$j]->move_camera != null){
  2939. array_push($data,[
  2940. 'area'=>$risk_list[$j]->area_title,
  2941. 'index'=>$index,
  2942. 'risk_type'=>$risk_type[$i],
  2943. 'risk_level'=>$risk_list[$j]->risk_level,
  2944. 'unit'=>$risk_list[$j]->coal_title,
  2945. 'content'=>$risk_list[$j]->risk_name ."★",
  2946. 'people_count'=>$risk_list[$j]->work_num,
  2947. 'work_location'=>$risk_list[$j]->risk_location,
  2948. 'leader'=>$risk_list[$j]->work_people
  2949. ]);
  2950. }else{
  2951. array_push($data,[
  2952. 'area'=>$risk_list[$j]->area_title,
  2953. 'index'=>$index,
  2954. 'risk_type'=>$risk_type[$i],
  2955. 'risk_level'=>$risk_list[$j]->risk_level,
  2956. 'unit'=>$risk_list[$j]->coal_title,
  2957. 'content'=>$risk_list[$j]->risk_name,
  2958. 'people_count'=>$risk_list[$j]->work_num,
  2959. 'work_location'=>$risk_list[$j]->risk_location,
  2960. 'leader'=>$risk_list[$j]->work_people
  2961. ]);
  2962. }
  2963. }
  2964. if($risk_list[$j]->risk_level == 2){
  2965. $nd_di++;
  2966. }
  2967. }
  2968. }
  2969. }
  2970. if(count($data) > 0){
  2971. for($x=0;$x<count($data);$x++){
  2972. if($data[$x]['risk_level'] == 0){
  2973. $data[$x]['risk_level'] = '高风险'.$count_gao.'项';
  2974. }
  2975. if($data[$x]['risk_level'] == 1){
  2976. $data[$x]['risk_level'] = '中风险'.$count_zhong.'项';
  2977. }
  2978. }
  2979. for($x=0;$x<count($data);$x++){
  2980. array_push($type_list,$data[$x]);
  2981. }
  2982. }
  2983. }
  2984. for($i=0;$i<count($risk_type);$i++){
  2985. $count_gao = 0;
  2986. $count_zhong = 0;
  2987. $data = [];
  2988. if(count($risk_list) > 0){
  2989. for($j=0;$j<count($risk_list);$j++){
  2990. if($risk_list[$j]->area_id == '1055262899082551297' && $risk_list[$j]->risk_type == $i){
  2991. if($risk_list[$j]->risk_level == 0){
  2992. $count_gao++;
  2993. $tx_gao++;
  2994. }
  2995. if($risk_list[$j]->risk_level == 1){
  2996. $count_zhong++;
  2997. $tx_zhong++;
  2998. }
  2999. if($risk_list[$j]->risk_level != 2){
  3000. $index++;
  3001. if ($risk_list[$j]->move_camera != null){
  3002. array_push($data,[
  3003. 'area'=>$risk_list[$j]->area_title,
  3004. 'index'=>$index,
  3005. 'risk_type'=>$risk_type[$i],
  3006. 'risk_level'=>$risk_list[$j]->risk_level,
  3007. 'unit'=>$risk_list[$j]->coal_title,
  3008. 'content'=>$risk_list[$j]->risk_name ."★",
  3009. 'people_count'=>$risk_list[$j]->work_num,
  3010. 'work_location'=>$risk_list[$j]->risk_location,
  3011. 'leader'=>$risk_list[$j]->work_people
  3012. ]);
  3013. }else{
  3014. array_push($data,[
  3015. 'area'=>$risk_list[$j]->area_title,
  3016. 'index'=>$index,
  3017. 'risk_type'=>$risk_type[$i],
  3018. 'risk_level'=>$risk_list[$j]->risk_level,
  3019. 'unit'=>$risk_list[$j]->coal_title,
  3020. 'content'=>$risk_list[$j]->risk_name,
  3021. 'people_count'=>$risk_list[$j]->work_num,
  3022. 'work_location'=>$risk_list[$j]->risk_location,
  3023. 'leader'=>$risk_list[$j]->work_people
  3024. ]);
  3025. }
  3026. }
  3027. if($risk_list[$j]->risk_level == 2){
  3028. $tx_di++;
  3029. }
  3030. }
  3031. }
  3032. }
  3033. if(count($data) > 0){
  3034. for($x=0;$x<count($data);$x++){
  3035. if($data[$x]['risk_level'] == 0){
  3036. $data[$x]['risk_level'] = '高风险'.$count_gao.'项';
  3037. }
  3038. if($data[$x]['risk_level'] == 1){
  3039. $data[$x]['risk_level'] = '中风险'.$count_zhong.'项';
  3040. }
  3041. }
  3042. for($x=0;$x<count($data);$x++){
  3043. array_push($type_list,$data[$x]);
  3044. }
  3045. }
  3046. }
  3047. $result_list = [];
  3048. if(isset($params['mark'])){
  3049. $mark = $params['mark'];
  3050. if ($mark == 0){
  3051. foreach ($type_list as $item) {
  3052. if ($item["area"] == "宁东片区") {
  3053. $result_list[] = $item;
  3054. }
  3055. }
  3056. $result['type_list'] = $result_list;
  3057. }elseif ($mark == 1){
  3058. foreach ($type_list as $item) {
  3059. if ($item["area"] == "太西片区") {
  3060. $result_list[] = $item;
  3061. }
  3062. }
  3063. $result['type_list'] = $result_list;
  3064. }else{
  3065. $result['type_list'] = $type_list;
  3066. }
  3067. }else{
  3068. $result['type_list'] = $type_list;
  3069. }
  3070. if($nd_gao != 0){
  3071. $nd_gao = '高风险作业'.$nd_gao.'项,';
  3072. }else{
  3073. $nd_gao = '无高风险作业,';
  3074. }
  3075. if($nd_zhong != 0){
  3076. $nd_zhong = '中风险作业'.$nd_zhong.'项,';
  3077. }else{
  3078. $nd_zhong = '无中风险作业,';
  3079. }
  3080. if($nd_di != 0){
  3081. $nd_di = '低风险作业'.$nd_di.'项;';
  3082. }else{
  3083. $nd_di = '无低风险作业;';
  3084. }
  3085. if($tx_gao != 0){
  3086. $tx_gao = '高风险作业'.$tx_gao.'项,';
  3087. }else{
  3088. $tx_gao = '无高风险作业,';
  3089. }
  3090. if($tx_zhong != 0){
  3091. $tx_zhong = '中风险作业'.$tx_zhong.'项,';
  3092. }else{
  3093. $tx_zhong = '无中风险作业,';
  3094. }
  3095. if($tx_di != 0){
  3096. $tx_di = '低风险作业'.$tx_di.'项;';
  3097. }else{
  3098. $tx_di = '无低风险作业;';
  3099. }
  3100. $result['remark'] = '备注:宁东片区'.$nd_gao.$nd_zhong.$nd_di.'太西片区'.$tx_gao.$tx_zhong.$tx_di;
  3101. return $result;
  3102. }
  3103. //导出摄像头表
  3104. public function export2Camera(Request $request){
  3105. $params = $request->all();
  3106. // $result['camera_list'] = [];
  3107. $camera_list = [];
  3108. $index = 0;
  3109. if(isset($params['date'])){
  3110. $date = $params['date'];
  3111. }else{
  3112. $date = date('Y-m-d');
  3113. }
  3114. $coal_list = DB::connection('mysql_fwe10')->table('uf_xx_coal_washery as t')
  3115. ->select('t.*','t1.title as area_title')
  3116. ->leftJoin('uf_xx_area as t1','t1.id','=','t.area_id')
  3117. ->where('t.is_delete',0)
  3118. ->orderBy('t1.create_time')
  3119. ->orderBy('t.sort')
  3120. ->where('t.is_delete',0)
  3121. ->where('t.delete_type',0)
  3122. ->where('t1.is_delete',0)
  3123. ->where('t1.delete_type',0)
  3124. ->get();
  3125. $risk_list = DB::connection('mysql_fwe10')
  3126. ->table('uf_xx_risk_assignment as t')
  3127. ->where('risk_level',2)
  3128. ->whereDate('create_time', $date)
  3129. ->where('t.is_delete', 0)
  3130. ->where('t.current_step','结束节点')
  3131. ->where('t.delete_type',0)
  3132. ->whereNotNull('flow_id')
  3133. ->where('move_camera','!=',null)
  3134. ->orderBy('create_time')->get();
  3135. $risk_dict = [];
  3136. foreach ($risk_list as $key => $value) {
  3137. $risk_dict[$value->coal_washery_id][] = $value;
  3138. }
  3139. foreach ($coal_list as $key => $value) {
  3140. try {
  3141. if(isset($risk_dict[$value->ID]) && !empty($risk_dict[$value->ID])) {
  3142. $risk = $risk_dict[$value->ID];
  3143. foreach ($risk as $k => $v) {
  3144. $index++;
  3145. array_push($camera_list,[
  3146. 'area'=>$value->area_title,
  3147. 'unit'=>$value->title,
  3148. 'index'=>$index,
  3149. 'people_num'=>$v->work_num,
  3150. 'content'=>$v->risk_name,
  3151. 'work_location'=>$v->risk_location,
  3152. 'leader'=>$v->work_people,
  3153. ]);
  3154. // $result['camera_list'][] = [
  3155. // 'area'=>$value->area_title,
  3156. // 'unit'=>$value->title,
  3157. // 'index'=>$index,
  3158. // 'people_num'=>$v->work_num,
  3159. // 'content'=>$v->risk_name,
  3160. // 'work_location'=>$v->risk_location,
  3161. // 'leader'=>$v->work_people,
  3162. // ];
  3163. }
  3164. }
  3165. } catch (Exception $e) {
  3166. echo $e->getMessage();
  3167. }
  3168. }
  3169. $result_list = [];
  3170. if(isset($params['mark'])){
  3171. $mark = $params['mark'];
  3172. if ($mark == 0){
  3173. foreach ($camera_list as $item) {
  3174. if ($item["area"] == "宁东片区") {
  3175. $result_list[] = $item;
  3176. }
  3177. }
  3178. $result['camera_list'] = $result_list;
  3179. }elseif ($mark == 1){
  3180. foreach ($camera_list as $item) {
  3181. if ($item["area"] == "太西片区") {
  3182. $result_list[] = $item;
  3183. }
  3184. }
  3185. $result['camera_list'] = $result_list;
  3186. }else{
  3187. $result['camera_list'] = $type_list;
  3188. }
  3189. }else{
  3190. $result['camera_list'] = $camera_list;
  3191. }
  3192. return $result;
  3193. }
  3194. //导出完成情况表统计
  3195. public function export3Total(Request $request){
  3196. $params = $request->all();
  3197. $result = '';
  3198. if(isset($params['date'])){
  3199. $date = $params['date'];
  3200. }else{
  3201. $date = date('Y-m-d');
  3202. }
  3203. $risk_data = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment as t')
  3204. ->select('t.*','t2.title')
  3205. ->leftJoin('uf_xx_coal_washery as t1', 't.coal_washery_id', '=', 't1.id')
  3206. ->leftJoin('uf_xx_area as t2', 't1.area_id', '=', 't2.id')
  3207. ->whereDate('t.fill_date', $date)
  3208. ->where('t.is_delete',0)
  3209. ->where('t.wcqk',0)
  3210. ->where('t.is_delete',0)
  3211. ->where('t.delete_type',0)
  3212. ->where('t.current_step','结束节点')
  3213. ->whereNotNull('t.flow_id')
  3214. ->get();
  3215. $level_arr = [
  3216. 'gao'=>[
  3217. 'title'=>'高',
  3218. 'con'=>0,
  3219. 'nd'=>0,
  3220. 'tx'=>0
  3221. ],
  3222. 'zhong'=>[
  3223. 'title'=>'中',
  3224. 'con'=>0,
  3225. 'nd'=>0,
  3226. 'tx'=>0
  3227. ],
  3228. 'di'=>[
  3229. 'title'=>'低',
  3230. 'con'=>0,
  3231. 'nd'=>0,
  3232. 'tx'=>0
  3233. ]
  3234. ];
  3235. foreach ($risk_data as $key => $value) {
  3236. $risk_level = $value->risk_level;
  3237. if ($risk_level == 0) {
  3238. ++$level_arr['gao']['con'];
  3239. if ($value->title == '宁东片区') {
  3240. ++$level_arr['gao']['nd'];
  3241. } else if ($value->title == '太西片区') {
  3242. ++$level_arr['gao']['tx'];
  3243. }
  3244. } else if ($risk_level == 1) {
  3245. ++$level_arr['zhong']['con'];
  3246. if ($value->title == '宁东片区') {
  3247. ++$level_arr['zhong']['nd'];
  3248. } else if ($value->title == '太西片区') {
  3249. ++$level_arr['zhong']['tx'];
  3250. }
  3251. } else {
  3252. ++$level_arr['di']['con'];
  3253. if ($value->title == '宁东片区') {
  3254. ++$level_arr['di']['nd'];
  3255. } else if ($value->title == '太西片区') {
  3256. ++$level_arr['di']['tx'];
  3257. }
  3258. }
  3259. }
  3260. foreach ($level_arr as $key => $value) {
  3261. // 不需要低风险
  3262. if ($key == 'di') continue;
  3263. $con = $value['con'];
  3264. $con_nd = $value['nd'];
  3265. $con_tx = $value['tx'];
  3266. $title = $value['title'];
  3267. if ($con > 0) {
  3268. $result .= $title.'风险' . $con . '项';
  3269. $str = '';
  3270. if($con_nd > 0){
  3271. $str = $str.'宁东'.$con_nd.'项,';
  3272. }
  3273. if($con_tx > 0){
  3274. $str = $str.'太西'.$con_tx.'项,';
  3275. }
  3276. $str = rtrim($str, ",");
  3277. $result = $result . '('.$str.')、';
  3278. }
  3279. }
  3280. $result = rtrim($result, "、");
  3281. $data['describe'] = $result;
  3282. return $data;
  3283. }
  3284. //导出完成情况表自营列表
  3285. public function export3ListZiying(Request $request){
  3286. $params = $request->all();
  3287. $result['ziying_list'] = [];
  3288. if(isset($params['date'])){
  3289. $date = $params['date'];
  3290. }else{
  3291. $date = date('Y-m-d');
  3292. }
  3293. $coal_list = DB::connection('mysql_fwe10')
  3294. ->table('uf_xx_coal_washery as t')
  3295. ->where('obj_type',0)
  3296. ->where('t.is_delete',0)
  3297. ->where('t.delete_type',0)
  3298. ->orderBy('sort')->get();
  3299. // 以下的优化方式有问题,接口报错
  3300. // 1. foreach 循环后的 $risk_list_list 与 $risk_list_data 数据量不同
  3301. // 2. $risk_list 不能使用 count()函数统计个数
  3302. // $risk_list_data = DB::connection('mysql_fwe10')
  3303. // ->table('uf_xx_risk_assignment as t')
  3304. // ->whereDate('create_time', $date)
  3305. //// ->where('coal_washery_id',$coal_list[$i]->ID)
  3306. // ->where('wcqk',0)
  3307. // ->where('t.is_delete',0)
  3308. // ->where('t.delete_type',0)
  3309. // ->where('t.current_step','结束节点')
  3310. // ->whereNotNull('t.flow_id')
  3311. // ->orderBy('create_time')->get();
  3312. // $risk_list_list = [];
  3313. // foreach ($risk_list_data as $key => $value) {
  3314. // $risk_list_list[$value['coal_washery_id']] = $value;
  3315. // }
  3316. if(count($coal_list) > 0){
  3317. for($i=0;$i<count($coal_list);$i++){
  3318. $risk_list = DB::connection('mysql_fwe10')
  3319. ->table('uf_xx_risk_assignment as t')
  3320. ->whereDate('fill_date', $date)
  3321. ->where('IS_DELETE', 0)
  3322. ->where('coal_washery_id',$coal_list[$i]->ID)
  3323. ->where('wcqk',0)
  3324. ->where('t.is_delete',0)
  3325. ->where('t.delete_type',0)
  3326. ->where('t.current_step','结束节点')
  3327. ->whereNotNull('t.flow_id')
  3328. ->orderBy('create_time')->get();
  3329. // $id = $coal_list[$i]->ID;
  3330. // $risk_list = $risk_list_list[$id] ?? null;
  3331. if(count($risk_list) > 0){
  3332. $gao = 0;
  3333. $zhong = 0;
  3334. $di = 0;
  3335. for($j=0;$j<count($risk_list);$j++){
  3336. if($risk_list[$j]->risk_level == 0){
  3337. $gao = $gao + 1;
  3338. }
  3339. if($risk_list[$j]->risk_level == 1){
  3340. $zhong = $zhong + 1;
  3341. }
  3342. // if($risk_list[$j]->risk_level == 2){
  3343. // $di = $di + 1;
  3344. // }
  3345. }
  3346. if($gao > 0){
  3347. for($j=0;$j<count($risk_list);$j++){
  3348. if($risk_list[$j]->risk_level == 0){
  3349. array_push($result['ziying_list'],[
  3350. 'unit' => $coal_list[$i]->title,
  3351. 'risk_level' => '高风险'.$gao.'项',
  3352. 'content' => $risk_list[$j]->risk_name,
  3353. 'reason' => '按计划施工',
  3354. 'people' => $risk_list[$j]->work_people
  3355. ]);
  3356. }
  3357. }
  3358. }
  3359. if($zhong > 0){
  3360. for($j=0;$j<count($risk_list);$j++){
  3361. if($risk_list[$j]->risk_level == 1){
  3362. array_push($result['ziying_list'],[
  3363. 'unit' => $coal_list[$i]->title,
  3364. 'risk_level' => '中风险'.$zhong.'项',
  3365. 'content' => $risk_list[$j]->risk_name,
  3366. 'reason' => '按计划施工',
  3367. 'people' => $risk_list[$j]->work_people
  3368. ]);
  3369. }
  3370. }
  3371. }
  3372. // if($di > 0){
  3373. // for($j=0;$j<count($risk_list);$j++){
  3374. // if($risk_list[$j]->risk_level == 2){
  3375. // array_push($result['ziying_list'],[
  3376. // 'unit' => $coal_list[$i]->title,
  3377. // 'risk_level' => '低风险'.$di.'项',
  3378. // 'content' => $risk_list[$j]->risk_name,
  3379. // 'reason' => '按计划施工',
  3380. // 'people' => $risk_list[$j]->work_people
  3381. // ]);
  3382. // }
  3383. // }
  3384. // }
  3385. }
  3386. }
  3387. }
  3388. return $result;
  3389. }
  3390. //导出完成情况表委外列表
  3391. public function export3ListWeiwai(Request $request){
  3392. $params = $request->all();
  3393. $result['weiwai_list'] = [];
  3394. if(isset($params['date'])){
  3395. $date = $params['date'];
  3396. }else{
  3397. $date = date('Y-m-d');
  3398. }
  3399. $coal_list = DB::connection('mysql_fwe10')
  3400. ->table('uf_xx_coal_washery as t')
  3401. ->where('is_delete',0)
  3402. ->where('obj_type',1)
  3403. ->where('t.is_delete',0)
  3404. ->where('t.delete_type',0)
  3405. ->orderBy('sort')->get();
  3406. if(count($coal_list) > 0){
  3407. for($i=0;$i<count($coal_list);$i++){
  3408. $risk_list = DB::connection('mysql_fwe10')
  3409. ->table('uf_xx_risk_assignment as t')
  3410. ->whereDate('fill_date', $date)
  3411. ->where('IS_DELETE', 0)
  3412. ->where('coal_washery_id',$coal_list[$i]->ID)
  3413. ->where('wcqk',0)
  3414. ->where('t.is_delete',0)
  3415. ->where('t.delete_type',0)
  3416. ->where('t.current_step','结束节点')
  3417. ->whereNotNull('t.flow_id')
  3418. ->orderBy('create_time')->get();
  3419. if(count($risk_list) > 0){
  3420. $gao = 0;
  3421. $zhong = 0;
  3422. $di = 0;
  3423. for($j=0;$j<count($risk_list);$j++){
  3424. if($risk_list[$j]->risk_level == 0){
  3425. $gao = $gao + 1;
  3426. }
  3427. if($risk_list[$j]->risk_level == 1){
  3428. $zhong = $zhong + 1;
  3429. }
  3430. // if($risk_list[$j]->risk_level == 2){
  3431. // $di = $di + 1;
  3432. // }
  3433. }
  3434. if($gao > 0){
  3435. for($j=0;$j<count($risk_list);$j++){
  3436. if($risk_list[$j]->risk_level == 0){
  3437. array_push($result['weiwai_list'],[
  3438. 'unit' => $coal_list[$i]->title,
  3439. 'risk_level' => '高风险'.$gao.'项',
  3440. 'content' => $risk_list[$j]->risk_name,
  3441. 'reason' => '按计划施工',
  3442. 'people' => $risk_list[$j]->work_people
  3443. ]);
  3444. }
  3445. }
  3446. }
  3447. if($zhong > 0){
  3448. for($j=0;$j<count($risk_list);$j++){
  3449. if($risk_list[$j]->risk_level == 1){
  3450. array_push($result['weiwai_list'],[
  3451. 'unit' => $coal_list[$i]->title,
  3452. 'risk_level' => '中风险'.$zhong.'项',
  3453. 'content' => $risk_list[$j]->risk_name,
  3454. 'reason' => '按计划施工',
  3455. 'people' => $risk_list[$j]->work_people
  3456. ]);
  3457. }
  3458. }
  3459. }
  3460. // if($di > 0){
  3461. // for($j=0;$j<count($risk_list);$j++){
  3462. // if($risk_list[$j]->risk_level == 2){
  3463. // array_push($result['weiwai_list'],[
  3464. // 'unit' => $coal_list[$i]->title,
  3465. // 'risk_level' => '低风险'.$di.'项',
  3466. // 'content' => $risk_list[$j]->risk_name,
  3467. // 'reason' => '按计划施工',
  3468. // 'people' => $risk_list[$j]->work_people
  3469. // ]);
  3470. // }
  3471. // }
  3472. // }
  3473. }
  3474. }
  3475. }
  3476. return $result;
  3477. }
  3478. //导出盯控次数统计表
  3479. public function export4(Request $request){
  3480. $params = $request->all();
  3481. if(isset($params['start_time']) && isset($params['end_time'])){
  3482. $start_time = $params['start_time'];
  3483. $end_time = $params['end_time'];
  3484. }else{
  3485. $start_time = date('Y-m-d 00:00:00');
  3486. $end_time = date('Y-m-d 00:00:00', strtotime('+1 day'));
  3487. }
  3488. $result = [];
  3489. $index = 0;
  3490. $risk_data = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment as t')
  3491. ->select('t.*','t2.title as area','t1.title','t1.sort')
  3492. ->leftJoin('uf_xx_coal_washery as t1', 't.coal_washery_id', '=', 't1.id')
  3493. ->leftJoin('uf_xx_area as t2', 't1.area_id', '=', 't2.id')
  3494. ->whereBetween('t.create_time', [$start_time, $end_time])
  3495. ->where('t.is_delete',0)
  3496. ->where('t.delete_type',0)
  3497. ->where('t.current_step','结束节点')
  3498. ->whereNotNull('t.flow_id')
  3499. ->orderBy('t1.sort')
  3500. ->get();
  3501. $people_data = DB::connection('mysql_fwe10')->table('uf_xx_dkry as t')
  3502. ->select('t.xm','t.sort')
  3503. ->where('t.is_delete',0)
  3504. ->where('t.delete_type',0)
  3505. ->orderBy('t.sort')
  3506. ->get();
  3507. $people_map = [];
  3508. foreach ($people_data as $key => $value){
  3509. // dd($value);
  3510. $people_map[$value->xm] = 1;
  3511. }
  3512. // dd($people_map);
  3513. if(count($risk_data) > 0){
  3514. for($i=0;$i<count($risk_data);$i++){
  3515. $people = explode('、',$risk_data[$i]->work_people);
  3516. if(count($people) > 1){//多人
  3517. for($j=0;$j<count($people);$j++){
  3518. if (!isset($people_map[$people[$j]])) continue;
  3519. $result[$index]['area'] = $risk_data[$i]->area;
  3520. $result[$index]['unit'] = $risk_data[$i]->title;
  3521. $work_num = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereBetween('create_time', [$start_time, $end_time])->where('is_delete',0)->where('delete_type',0)->whereNotNull('flow_id')->where('coal_washery_id',$risk_data[$i]->coal_washery_id)->count();
  3522. $result[$index]['work_num'] = $work_num;
  3523. $result[$index]['work_people'] = $people[$j];
  3524. $result[$index]['control_num'] = 1;
  3525. $result[$index]['account'] = 0;
  3526. $result[$index]['sort'] = $risk_data[$i]->sort;
  3527. $index++;
  3528. }
  3529. }else{//单人
  3530. if (!isset($people_map[$risk_data[$i]->work_people])) continue;
  3531. $result[$index]['area'] = $risk_data[$i]->area;
  3532. $result[$index]['unit'] = $risk_data[$i]->title;
  3533. $work_num = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')->whereBetween('create_time', [$start_time, $end_time])->where('is_delete',0)->where('delete_type',0)->whereNotNull('flow_id')->where('coal_washery_id',$risk_data[$i]->coal_washery_id)->count();
  3534. $result[$index]['work_num'] = $work_num;
  3535. $result[$index]['work_people'] = $risk_data[$i]->work_people;
  3536. $result[$index]['control_num'] = 1;
  3537. $result[$index]['account'] = 0;
  3538. $result[$index]['sort'] = $risk_data[$i]->sort;
  3539. $index++;
  3540. }
  3541. }
  3542. }
  3543. if(count($result) > 0){
  3544. $workPeopleValues = array_column($result, 'work_people');
  3545. $counts = array_count_values($workPeopleValues);
  3546. for($i=0;$i<count($result);$i++){
  3547. $result[$i]['control_num'] = $counts[$result[$i]['work_people']];
  3548. }
  3549. for($i=0;$i<count($result);$i++){
  3550. $num = $result[$i]['control_num']/$result[$i]['work_num'];
  3551. $num = number_format($num, 2)*100;
  3552. $result[$i]['account'] = $num;
  3553. }
  3554. usort($result, function ($a, $b) {
  3555. return $b['account'] <=> $a['account'];
  3556. });
  3557. $rank = 1;
  3558. for ($i = 0; $i < count($result); $i++) {
  3559. // 对于同一个 control_num 赋予相同的排名
  3560. if ($i > 0 && $result[$i]['account'] == $result[$i - 1]['account']) {
  3561. $result[$i]['rank'] = $result[$i - 1]['rank']; // 保持相同排名
  3562. } else {
  3563. $result[$i]['rank'] = $rank++; // 否则递增排名
  3564. }
  3565. }
  3566. usort($result, function ($a, $b) {
  3567. return $a['sort'] <=> $b['sort'];
  3568. });
  3569. $result = array_map(function ($item) {
  3570. unset($item['sort']);
  3571. return $item;
  3572. }, $result);
  3573. for ($i = 0; $i < count($result); $i++) {
  3574. $result[$i]['account'] = $result[$i]['account'].'%';
  3575. }
  3576. }
  3577. $result = array_map("unserialize", array_unique(array_map("serialize", $result)));
  3578. $result = array_values($result);
  3579. $res['control_list'] = $result;
  3580. return $res;
  3581. }
  3582. //导出人均盯控次数统计表
  3583. public function export5(Request $request){
  3584. $params = $request->all();
  3585. if(isset($params['start_time']) && isset($params['end_time'])){
  3586. $start_time = $params['start_time'];
  3587. $end_time = $params['end_time'];
  3588. }else{
  3589. $start_time = date('Y-m-d 00:00:00');
  3590. $end_time = date('Y-m-d 00:00:00', strtotime('+1 day'));
  3591. }
  3592. $res = [];
  3593. $coal_list = DB::connection('mysql_fwe10')->table('uf_xx_coal_washery as c')
  3594. ->select('c.*','a.title as area')
  3595. ->leftJoin('uf_xx_area as a','a.id','=','c.area_id')
  3596. ->where('c.is_delete',0)
  3597. ->orderBy('c.sort')->get();
  3598. $people_data = DB::connection('mysql_fwe10')->table('uf_xx_dkry as t')
  3599. ->select('t.xm','t.sort')
  3600. ->where('t.is_delete',0)
  3601. ->where('t.delete_type',0)
  3602. ->orderBy('t.sort')
  3603. ->get();
  3604. $people_arr = [];
  3605. foreach ($people_data as $key => $value){
  3606. $people_arr[] = $value->xm;
  3607. }
  3608. $risk_list = DB::connection('mysql_fwe10')->table('uf_xx_risk_assignment')
  3609. ->whereBetween('create_time', [$start_time, $end_time])
  3610. ->where('is_delete',0)
  3611. ->where('current_step','结束节点')
  3612. ->where('delete_type',0)
  3613. ->whereNotNull('flow_id')
  3614. // ->where('coal_washery_id',$coal_list[$i]->ID)
  3615. ->get();
  3616. $risk_list_map = [];
  3617. foreach ($risk_list as $key => $val) {
  3618. $risk_list_map[$val->coal_washery_id][] = $val;
  3619. }
  3620. if(count($coal_list) > 0){
  3621. for($i=0;$i<count($coal_list);$i++){
  3622. $coal_list_id = $coal_list[$i]->ID;
  3623. $risk_list = $risk_list_map[$coal_list_id] ?? null;
  3624. $var_1 = DB::connection('mysql_fwe10')->table('uf_xx_dkry as t')
  3625. ->select('t.xm')
  3626. ->where('t.is_delete',0)
  3627. ->where('t.delete_type',0)
  3628. ->where('coal_washery_id',$coal_list_id)
  3629. ->get();
  3630. $var2 = count($var_1);
  3631. if($risk_list && count($risk_list) > 0){
  3632. $control_num = 0;
  3633. for ($j=0;$j<count($risk_list);$j++){
  3634. $people = explode('、',$risk_list[$j]->work_people);
  3635. $control_num += count(array_intersect($people, $people_arr));
  3636. }
  3637. $res[$i]['area'] = $coal_list[$i]->area;
  3638. $res[$i]['unit'] = $coal_list[$i]->title;
  3639. $res[$i]['work_num'] = count($risk_list);
  3640. $res[$i]['control_num'] = $control_num;
  3641. $res[$i]['people_num'] = $var2;
  3642. $res[$i]['people_avg_count'] = $var2 > 0 ? number_format($control_num/$var2, 2) : 0;
  3643. $res[$i]['sort'] = $coal_list[$i]->sort;
  3644. }else{
  3645. $res[$i]['area'] = $coal_list[$i]->area;
  3646. $res[$i]['unit'] = $coal_list[$i]->title;
  3647. $res[$i]['work_num'] = 0;
  3648. $res[$i]['control_num'] = 0;
  3649. $res[$i]['people_num'] = $var2;
  3650. $res[$i]['people_avg_count'] = 0;
  3651. $res[$i]['sort'] = $coal_list[$i]->sort;
  3652. }
  3653. }
  3654. }
  3655. //按照people_avg_count排序
  3656. usort($res, function ($a, $b) {
  3657. return $b['people_avg_count'] <=> $a['people_avg_count'];
  3658. });
  3659. //添加排名rank
  3660. $rank = 1;
  3661. for ($i = 0; $i < count($res); $i++) {
  3662. // 对于同一个 control_num 赋予相同的排名
  3663. if ($i > 0 && $res[$i]['people_avg_count'] == $res[$i - 1]['people_avg_count']) {
  3664. $res[$i]['rank'] = $res[$i - 1]['rank']; // 保持相同排名
  3665. } else {
  3666. $res[$i]['rank'] = $rank++; // 否则递增排名
  3667. }
  3668. }
  3669. //按照sort排序
  3670. usort($res, function ($a, $b) {
  3671. return $a['sort'] <=> $b['sort'];
  3672. });
  3673. //删除sort字段
  3674. $res = array_map(function ($item) {
  3675. unset($item['sort']);
  3676. return $item;
  3677. }, $res);
  3678. $result['control_list'] = $res;
  3679. return $result;
  3680. }
  3681. //图片上传
  3682. public function uploadImg(Request $request){
  3683. $file = $request->file('file');
  3684. $file_name = CameraServices::uploadFile($file);
  3685. $file_path = public_path() . '/filedownload/';
  3686. $res = CameraServices::uploadOssFile($file_name, $file_path);
  3687. CameraServices::delUploadFile();
  3688. $result['image_path'] = $res;
  3689. return $this->success($result);
  3690. }
  3691. }