CameraApiController.php 82 KB

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