CameraApiController.php 79 KB

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