CameraApiController.php 79 KB

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