| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972 |
- <?php
- /**
- * Created by PhpStorm.
- * User: qiuzijian
- * Date: 2021-04-25
- * Time: 09:53
- */
- namespace Modules\Camera\Http\Controllers\Api;
- use App\Enum\ApiEnum;
- use App\Http\Controllers\Api\BaseController;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Config;
- use Illuminate\Support\Facades\Input;
- use Illuminate\Support\Facades\Log;
- use Modules\Camera\Entities\CameraList;
- use Modules\Camera\Enum\CameraEnum;
- use Modules\Camera\Http\Controllers\Api\TdwyController;
- use Modules\Camera\Services\CameraServices;
- use Modules\Mine\Entities\MineList;
- use Modules\Mine\Entities\MineListExt;
- use DB;
- use OSS\OssClient;
- class CameraApiController extends BaseController
- {
- //通过摄像头类型获取摄像头
- public function getCameraByType(){
- $mine_code = Input::get('mine_code', '');
- $camera_type = Input::get('camera_type', '');
- if (!$mine_code || !$camera_type) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $mine = DB::table('mine_list')->where('slug','like','%'.$mine_code.'%')->where('parent_id',0)->where('deleted_at',null)->first();
- if (!$mine) {
- $result['status'] = false;
- $result['msg'] = '矿区名称不存在';
- return $result;
- }
- $mine_list = DB::table('mine_list')->where('degree', 'like', $mine->id . '|' . '%')->where('deleted_at',null)->get();
- $mine_array = [];
- foreach($mine_list as $k=>$v){
- $mine_array[] = $v->id;
- }
- $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();
- if (!$query) {
- $result['status'] = false;
- $result['msg'] = '矿区下没有摄像头';
- return $result;
- }
- $result = [];
- foreach($query as $k=>$v){
- $result[$k]['id'] = $v->id;
- $result[$k]['mine_id'] = $v->mine_id;
- $result[$k]['camera_name'] = $v->camera_name;
- $result[$k]['cover_picture'] = $v->cover_picture;
- $result[$k]['camera_status'] = $v->camera_status;
- $result[$k]['playback'] = $v->playback;
- }
- return self::successResponse($result);
- }
- //宁煤摄像头统计
- public function getTotalNingmei(){
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- //宁煤集团
- $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
- $ydjk = DB::table('mine_list')->where('title','移动监控')->where('deleted_at',null)->get();
- $ydjk_list = [];
- if(count($ydjk) > 0){
- for($i=0;$i<count($ydjk);$i++){
- array_push($ydjk_list,$ydjk[$i]->id);
- }
- }
- $ydjk_son = DB::table('mine_list')->whereIn('parent_id',$ydjk_list)->where('deleted_at',null)->get();
- if(count($ydjk_son) > 0){
- for($i=0;$i<count($ydjk_son);$i++){
- array_push($ydjk_list,$ydjk_son[$i]->id);
- }
- }
- $mine_all = DB::table('mine_list')->where('deleted_at',null)->whereNotIn('id',$ydjk_list)->get();//所有区域
- $mine_ningmei = [];//宁煤集团所有区域
- foreach($mine_all as $k=>$v){
- if(explode('|',$v->degree)[0] == $ningmei[0]->id){
- $mine_ningmei[] = $v->id;
- }
- }
- //宁煤在离线数量
- $data[0]['title'] = '宁煤公司';
- $data[0]['mine_code'] = $ningmei[0]->slug;
- $data[0]['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('deleted_at',null)->count();
- $data[0]['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('camera_status',1)->where('deleted_at',null)->count();
- $data[0]['total_offline'] = $data[0]['total'] - $data[0]['total_online'];
- $data[0]['rate'] = round($data[0]['total_online'] / $data[0]['total'] * 100,2)."%";
- //宁煤下各矿在离线数量
- $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('deleted_at',null)->get();
- foreach($mine_list as $k => $v){
- $mine_use = [];//宁煤下每个矿所有区域
- foreach($mine_all as $key=>$value){
- if(count(explode('|',$value->degree)) > 1){
- if(explode('|',$value->degree)[0] == $ningmei[0]->id && explode('|',$value->degree)[1] == $v->id){
- $mine_use[] = $value->id;
- }
- }
- }
- $total = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('deleted_at',null)->count();
- $total_online = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('camera_status',1)->where('deleted_at',null)->count();
- if($total == 0){
- $rate = "0%";
- }else{
- $rate = round($total_online / $total * 100,2)."%";
- }
- if($v->slug == 'NingXiaMeiYeTeShuZuoYeJianKongShiPin'){
- $res['title'] = $v->title;
- $res['mine_code'] = $v->slug."_jituan";
- $res['total'] = $total;
- $res['total_online'] = $total_online;
- $res['total_offline'] = $total - $total_online;
- $res['rate'] = $rate;
- }else{
- if($v->slug == 'ShuiDianFenGongSi'){
- $v->title = '供电分公司';
- }
- array_push($data,[
- 'title'=>$v->title,
- 'mine_code'=>$v->slug."_jituan",
- 'total'=>$total,
- 'total_online'=>$total_online,
- 'total_offline'=>$total - $total_online,
- 'rate'=>$rate
- ]);
- }
- }
- if(isset($res)){
- array_push($data,[
- 'title'=>$res['title'],
- 'mine_code'=>$res['mine_code'],
- 'total'=>$res['total'],
- 'total_online'=>$res['total_online'],
- 'total_offline'=>$res['total_offline'],
- 'rate'=>$res['rate']
- ]);
- }
- return self::successResponse($data);
- }
- //宁煤摄像头统计字符串
- public function getTotalString(){
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- //宁煤集团
- $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
- $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
- $mine_ningmei = [];//宁煤集团所有区域
- foreach($mine_all as $k=>$v){
- if(explode('|',$v->degree)[0] == $ningmei[0]->id){
- $mine_ningmei[] = $v->id;
- }
- }
- //宁煤在离线数量
- $nm['title'] = '宁煤公司';
- $nm['mine_code'] = $ningmei[0]->slug;
- $nm['total'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('deleted_at',null)->count();
- $nm['total_online'] = DB::table('camera_list')->whereIn('mine_id',$mine_ningmei)->where('camera_status',1)->where('deleted_at',null)->count();
- $nm['total_offline'] = $nm['total'] - $nm['total_online'];
- $nm['rate'] = round($nm['total_online'] / $nm['total'] * 100,2);
- $data = [];
- //宁煤下各矿在离线数量
- $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('deleted_at',null)->get();
- foreach($mine_list as $k => $v){
- $mine_use = [];//宁煤下每个矿所有区域
- foreach($mine_all as $key=>$value){
- if(count(explode('|',$value->degree)) > 1){
- if(explode('|',$value->degree)[0] == $ningmei[0]->id && explode('|',$value->degree)[1] == $v->id){
- $mine_use[] = $value->id;
- }
- }
- }
- $total = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('deleted_at',null)->count();
- $total_online = DB::table('camera_list')->whereIn('mine_id',$mine_use)->where('is_show',1)->where('camera_status',1)->where('deleted_at',null)->count();
- if($total == 0){
- $rate = "0";
- }else{
- $rate = round($total_online / $total * 100,2);
- }
- if($v->slug == 'NingXiaMeiYeTeShuZuoYeJianKongShiPin'){
- $res['title'] = $v->title;
- $res['mine_code'] = $v->slug."_jituan";
- $res['total'] = $total;
- $res['total_online'] = $total_online;
- $res['total_offline'] = $total - $total_online;
- $res['rate'] = $rate;
- }else{
- array_push($data,[
- 'title'=>$v->title,
- 'mine_code'=>$v->slug."_jituan",
- 'total'=>$total,
- 'total_online'=>$total_online,
- 'total_offline'=>$total - $total_online,
- 'rate'=>$rate
- ]);
- }
- }
- if(isset($res)){
- array_push($data,[
- 'title'=>$res['title'],
- 'mine_code'=>$res['mine_code'],
- 'total'=>$res['total'],
- 'total_online'=>$res['total_online'],
- 'total_offline'=>$res['total_offline'],
- 'rate'=>$res['rate']
- ]);
- }
- $timestamp = strtotime(date('Y-m-d H:i:s'));
- $hour = date('G', $timestamp);
- $minute = date('i', $timestamp);
- $month = date('n', $timestamp);
- $day = date('j', $timestamp);
- if($minute == '00'){
- $minute = '';
- }
- if ($hour < 12) {
- $time = $month."月".$day."号上午".$hour."时".$minute;
- } elseif ($hour >= 12 && $hour < 18) {
- $time = $month."月".$day."号下午".$hour."时".$minute;
- } else {
- $time = $month."月".$day."号晚上".$hour."时".$minute;
- }
- $unit_max_name = '';
- $unit_max_rate = 0;
- $unit_min_name = '';
- $unit_min_rate = 100;
- $mzy_max_name = '';
- $mzy_max_rate = 0;
- $mzy_min_name = '';
- $mzy_min_rate = 100;
- $other_max_name = '';
- $other_max_rate = 0;
- $other_min_name = '';
- $other_min_rate = 100;
- if(count($data)>0){
- for($i=0;$i<count($data);$i++){
- if (strpos($data[$i]['title'], '煤矿') !== false || strpos($data[$i]['title'], '洗选') !== false) {
- if($data[$i]['rate'] > $unit_max_rate){
- $unit_max_rate = $data[$i]['rate'];
- }
- if($data[$i]['rate'] < $unit_min_rate){
- $unit_min_rate = $data[$i]['rate'];
- }
- }elseif(strpos($data[$i]['title'], '煤制油') !== false || strpos($data[$i]['title'], '烯烃') !== false || strpos($data[$i]['title'], '甲醇') !== false || strpos($data[$i]['title'], '精蜡') !== false){
- if($data[$i]['rate'] > $mzy_max_rate){
- $mzy_max_rate = $data[$i]['rate'];
- }
- if($data[$i]['rate'] < $mzy_min_rate){
- $mzy_min_rate = $data[$i]['rate'];
- }
- }else{
- if($data[$i]['rate'] > $other_max_rate){
- $other_max_rate = $data[$i]['rate'];
- }
- if($data[$i]['rate'] < $other_min_rate){
- $other_min_rate = $data[$i]['rate'];
- }
- }
- }
- for($i=0;$i<count($data);$i++){
- if (strpos($data[$i]['title'], '煤矿') !== false || strpos($data[$i]['title'], '洗选') !== false) {
- if($data[$i]['rate'] == $unit_max_rate){
- $unit_max_name = $unit_max_name.'、'.$data[$i]['title'];
- }
- if($data[$i]['rate'] == $unit_min_rate){
- $unit_min_name = $unit_max_name.'、'.$data[$i]['title'];
- }
- }elseif(strpos($data[$i]['title'], '煤制油') !== false || strpos($data[$i]['title'], '烯烃') !== false || strpos($data[$i]['title'], '甲醇') !== false || strpos($data[$i]['title'], '精蜡') !== false){
- if($data[$i]['rate'] == $mzy_max_rate){
- $mzy_max_name = $mzy_max_name.'、'.$data[$i]['title'];
- }
- if($data[$i]['rate'] == $mzy_min_rate){
- $mzy_min_name = $mzy_max_name.'、'.$data[$i]['title'];
- }
- }else{
- if($data[$i]['rate'] == $other_max_rate){
- $other_max_name = $other_max_name.'、'.$data[$i]['title'];
- }
- if($data[$i]['rate'] == $other_min_rate){
- $other_min_name = $other_max_name.'、'.$data[$i]['title'];
- }
- }
- }
- }
- $unit_max_name = mb_substr($unit_max_name, 1);
- $unit_min_name = mb_substr($unit_min_name, 1);
- $mzy_max_name = mb_substr($mzy_max_name, 1);
- $mzy_min_name = mb_substr($mzy_min_name, 1);
- $other_max_name = mb_substr($other_max_name, 1);
- $other_min_name = mb_substr($other_min_name, 1);
- $result['data'] = '本周公司视频摄像头在线数'.$nm['total_online'].'个,'.'在线率为'.$nm['rate'].'%('.$time
- .'统计)。其中:①煤炭生产建设单位在线率排名第一的单位是'.$unit_max_name.',在线率达到'.$unit_max_rate
- .'%;排名末位的单位是'.$unit_min_name.',在线率达到'.$unit_min_rate
- .'%。②煤制油化工单位在线率排名第一的单位是'.$mzy_max_name.',在线率达到'.$mzy_max_rate.'%;排名末位的单位是'
- .$mzy_min_name.',在线率达到'.$mzy_min_rate.'%。③其他单位在线率排名第一的单位是'.$other_max_name
- .',在线率达到'.$other_max_rate.'%;排名末位的单位是'.$other_min_name.',在线率达到'.$other_min_rate.'%。';
- return self::successResponse($result);
- }
- //宁煤不在线摄像头列表
- public function offlineList(){
- $mine_code = Input::get('mine_code', '');
- if (!$mine_code) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- //宁煤集团
- $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
- $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
- $mine_ningmei = [];//宁煤集团所有区域
- foreach($mine_all as $k=>$v){
- if(explode('|',$v->degree)[0] == $ningmei[0]->id){
- $mine_ningmei[] = $v->id;
- }
- }
- if(count(explode('_',$mine_code)) > 1){
- $mine_code = explode('_',$mine_code)[0];
- }
- $mine_list = DB::table('mine_list')->where('parent_id',0)->where('slug','like','%'.$mine_code.'%')->where('deleted_at',null)->get();
- //如果传参是宁煤显示全部
- if(isset($mine_list[0]->title) && $mine_list[0]->title == config('mine_hls')[0]){
- //宁煤在离线数量
- $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();
- return self::successResponse($offline_list);
- }
- //宁煤下各矿在离线数量
- $mine_list = DB::table('mine_list')->where('parent_id',$ningmei[0]->id)->where('slug','like','%'.$mine_code.'%')->where('deleted_at',null)->get();
- $total_offline = [];
- foreach($mine_list as $k => $v){
- $mine_use = [];//宁煤下每个矿所有区域
- foreach($mine_all as $key=>$value){
- if(count(explode('|',$value->degree)) > 1){
- if(explode('|',$value->degree)[0] == $ningmei[0]->id && explode('|',$value->degree)[1] == $v->id){
- $mine_use[] = $value->id;
- }
- }
- }
- $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();
- }
- return self::successResponse($total_offline);
- }
- //宁煤高风险摄像头
- public function getRiskNingmei(){
- $mine_code = Input::get('mine_code', '');
- if (!$mine_code) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- //宁煤集团
- $ningmei = DB::table('mine_list')->where('title',config('mine_hls'))->get();
- //宁煤集团下级单位
- $mine = DB::table('mine_list')
- ->where('parent_id',$ningmei[0]->id)
- ->where('slug','like','%'.$mine_code.'%')
- ->where('deleted_at',null)
- ->get();
- //子区域树形列表
- $child_list = DB::table('mine_list')->where('parent_id',$mine[0]->id)->where('deleted_at',null)->orderBy('sort','desc')->get();
- $risk_id = null;
- if(count($child_list)>0){
- $risk_id = $this->mineTree($child_list);
- }
- $mine_list = [];
- if($risk_id != null){
- $risk = DB::table('mine_list')->where('parent_id',$risk_id)->where('deleted_at',null)->get();
- if(count($risk) > 0){
- //有子区域
- $mine_list = $this->riskTree($risk,[]);
- }else{
- //没有子区域
- $mine_list[] = $risk_id;
- }
- }
- $camera_list = DB::table('camera_list')
- ->select('camera_list.*','mine_list.title')
- ->leftJoin('mine_list','camera_list.mine_id','=','mine_list.id')
- ->where('camera_list.deleted_at',null)
- ->whereIn('camera_list.mine_id',$mine_list)
- ->orderBy('sort', 'desc')->get();
- $result = [];
- foreach($camera_list as $k=>$v){
- $result[$k]['parent_id'] = $ningmei[0]->id;
- $result[$k]['camera_id'] = $v->id;
- $result[$k]['mine_name'] = $v->title;
- $result[$k]['camera_name'] = $v->camera_name;
- $result[$k]['cover_picture'] = $v->cover_picture;
- $result[$k]['camera_status'] = $v->camera_status;
- $result[$k]['base64'] = $v->base64;
- }
- return self::successResponse($result);
- }
- public function mineTree($regions)
- {
- $arr = null;
- foreach ($regions as $key => $value) {
- $risk = explode('高风险作业',$value->title);
- if (count($risk)>1){
- return $value->id;
- }
- $mine_child = DB::table('mine_list')->where('parent_id', $value->id)->where('deleted_at',null)->get();
- if (count($mine_child) > 0) {
- $arr = self::mineTree($mine_child, $value->id);
- if($arr != null){
- return $arr;
- }
- }
- }
- return $arr;
- }
- public function riskTree($regions,$risk_list)
- {
- foreach ($regions as $key => $value) {
- $risk_child = DB::table('mine_list')->where('parent_id', $value->id)->where('deleted_at',null)->get();
- if (count($risk_child) > 0) {
- $risk_list = array_merge($risk_list,self::riskTree($risk_child,[]));
- }else{
- $risk_list[] = $value->id;
- }
- }
- return $risk_list;
- }
- //高风险区域摄像头
- public function getCameraByMinecode(){
- $mine_code = Input::get('mine_code', '');
- if (!$mine_code) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $mine = DB::table('mine_list')->where('slug','like','%'.$mine_code.'%')->where('parent_id',0)->where('deleted_at',null)->first();
- if (!$mine) {
- $result['status'] = false;
- $result['msg'] = '矿区名称不存在';
- return $result;
- }
- $mine_list = DB::table('mine_list')->where('degree', 'like', $mine->id . '|' . '%')->where('title','like','%高风险%')->where('deleted_at',null)->get();
- $mine_array = [];
- foreach($mine_list as $k=>$v){
- $mine_child = DB::table('mine_list')->where('degree', 'like','%' . $v->id . '%')->where('deleted_at',null)->get();
- if(count($mine_child)>0){
- for($i=0;$i<count($mine_child);$i++){
- $mine_array[] = $mine_child[$i]->id;
- }
- }
- }
- $query = DB::table('camera_list')
- ->select('camera_list.*','mine_list.title')
- ->leftJoin('mine_list','camera_list.mine_id','=','mine_list.id')
- ->where('camera_list.deleted_at',null)
- ->whereIn('camera_list.mine_id',$mine_array)
- ->orderBy('sort', 'desc')->get();
- if (!$query) {
- $result['status'] = false;
- $result['msg'] = '矿区下没有摄像头';
- return $result;
- }
- $result = [];
- foreach($query as $k=>$v){
- $result[$k]['parent_id'] = $mine->id;
- $result[$k]['camera_id'] = $v->id;
- $result[$k]['mine_name'] = $v->title;
- $result[$k]['camera_name'] = $v->camera_name;
- $result[$k]['cover_picture'] = $v->cover_picture;
- $result[$k]['camera_status'] = $v->camera_status;
- }
- return self::successResponse($result);
- }
- /**
- * 作者: qiuzijian
- * 注释: 获取摄像头列表
- * @return \App\Http\Controllers\Api\JsonResponse
- */
- public function getCamerasList()
- {
- $parent_id = Input::get('parent_id', '');
- $mine_id = Input::get('mine_id', '');
- $camera_type = Input::get('camera_type', CameraEnum::CAMERA_TYPE_ALL);
- $surface_id = Input::get('surface_id', '');
- if (!$parent_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!in_array($camera_type, [CameraEnum::CAMERA_TYPE_NORMAL, CameraEnum::CAMERA_TYPE_ALL]) && !$surface_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- //判断是否使用海康视频服务器
- // $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
- // if ($is_hak) {
- // $result = CameraServices::getHaiKangCamera($parent_id, $mine_id, $camera_type);
- // } else {
- $result = CameraServices::getCameraListByMineId($mine_id, $camera_type, $parent_id, $surface_id);
- // }
- return self::successResponse($result);
- }
- /**
- * 作者: qiuzijian
- * 注释: 获取摄像头播放地址
- * @return \App\Http\Controllers\Api\JsonResponse
- */
- public function getCamerasUrl()
- {
- $parent_id = Input::get('parent_id', '');
- $camera_id = Input::get('camera_id', '');
- if (!$parent_id || !$camera_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- //判断摄像头来源是否为内网服务器
- $camera_source = CameraList::where('id', $camera_id)->value('camera_source');
- if ($camera_source == CameraEnum::CAMERA_SOURCE_3) {
- $result = CameraServices::getIntranetCameraUrl($camera_id);
- return self::successResponse($result);
- }
- //判断是否使用海康视频服务器
- $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
- //判断是否生成摄像头请求链接
- $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
- if ($is_hak && !$camera_url) {
- //判断是否是mine配置文件的矿区
- $mine_res = DB::table('mine_list')->where('id',$parent_id)->get();
- //天地伟业
- if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine'))){
- $result = CameraServices::getRtspTianDi($camera_id,$parent_id);
- //宁煤集团
- }elseif(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine_hls'))){
- $result = CameraServices::getHkHls($camera_id,$parent_id);
- }
- //大华摄像头
- elseif($is_hak == 2){
- //同步大华视频服务器摄像头
- $tdwy = new TdwyController();
- $result = $tdwy->dahuaRtsp($camera_id,$parent_id);
- }
- //信息技术中心测试ws协议
- // elseif($mine_res[0]-> slug == 'XinXiJiShuZhongXin'){
- // $result = CameraServices::getHkWs($camera_id,$parent_id);
- //
- // }
- //海康切片逻辑
- else{
- $result = CameraServices::downloadCameraFiles($parent_id, $camera_id);
- }
- } else {
- //判断硬盘录像机的有没有封面图,有的走easydrawin,没有的走ffmpeg
- $cover_picture = CameraList::where('id', $camera_id)->value('cover_picture');
- // if(!$cover_picture){
- //ffmpeg拉流获取首帧图片
- // $result = CameraServices::getCameraUrlByFfmpeg($camera_id);
- // }else{
- // $result = CameraServices::getCameraUrlByCameraId($camera_id);
- // $result = CameraServices::getRtspYingPan($camera_id);
- //硬盘录像机切片测试
- $result = CameraServices::getRtspQiePian($camera_id);
- // }
- }
- return self::successResponse($result);
- }
- public function getCamerasLanUrl()
- {
- $parent_id = Input::get('parent_id', '');
- $camera_id = Input::get('camera_id', '');
- if (!$parent_id || !$camera_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- //判断摄像头来源是否为内网服务器
- $camera_source = CameraList::where('id', $camera_id)->value('camera_source');
- if ($camera_source == CameraEnum::CAMERA_SOURCE_3) {
- $result = CameraServices::getIntranetCameraUrl($camera_id);
- return self::successResponse($result);
- }
- //判断是否使用海康视频服务器
- $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
- //判断是否生成摄像头请求链接
- $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
- if ($is_hak && !$camera_url) {
- //判断是否是mine配置文件的矿区
- $mine_res = DB::table('mine_list')->where('id',$parent_id)->get();
- //天地伟业
- if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine'))){
- $result = CameraServices::getRtspTianDi($camera_id,$parent_id);
- //宁煤集团
- }elseif(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine_hls'))){
- $result = CameraServices::getHkHls($camera_id,$parent_id);
- }else{
- $result = CameraServices::getLanCameraUrl($parent_id, $camera_id);
- }
- } else {
- //判断硬盘录像机的有没有封面图,有的走easydrawin,没有的走ffmpeg
- $cover_picture = CameraList::where('id', $camera_id)->value('cover_picture');
- // if(!$cover_picture){
- //ffmpeg拉流获取首帧图片
- // $result = CameraServices::getCameraUrlByFfmpeg($camera_id);
- // }else{
- $result = CameraServices::getCameraUrlByCameraId($camera_id);
- // }
- }
- return self::successResponse($result);
- }
- //获取海康rtsp流
- public function getHikRtsp(){
- $parent_id = Input::get('parent_id', '');
- $camera_id = Input::get('camera_id', '');
- if (!$parent_id || !$camera_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- //判断是否使用海康视频服务器
- $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
- //判断是否生成摄像头请求链接
- $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
- if ($is_hak == 1 && !$camera_url) {
- $result = CameraServices::getHkRtsp($camera_id,$parent_id);
- return self::successResponse($result);
- }else{
- return self::errorResponse(ApiEnum::HK_REQUEST_FAIL);
- }
- }
- //获取海康rtmp流
- public function getHikRtmp(){
- $parent_id = Input::get('parent_id', '');
- $camera_id = Input::get('camera_id', '');
- if (!$parent_id || !$camera_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- //判断是否使用海康视频服务器
- $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
- //判断是否生成摄像头请求链接
- $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
- if ($is_hak == 1 && !$camera_url) {
- $result = CameraServices::getHkRtmp($camera_id,$parent_id);
- return self::successResponse($result);
- }else{
- return self::errorResponse(ApiEnum::HK_REQUEST_FAIL);
- }
- }
- //海康摄像头easy_drawin方式获取url
- public function getCamerasRtsp()
- {
- $parent_id = Input::get('parent_id', '');
- $camera_id = Input::get('camera_id', '');
- if (!$parent_id || !$camera_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- //判断摄像头来源是否为内网服务器
- $camera_source = CameraList::where('id', $camera_id)->value('camera_source');
- if ($camera_source == CameraEnum::CAMERA_SOURCE_3) {
- $result = CameraServices::getIntranetCameraUrl($camera_id);
- return self::successResponse($result);
- }
- //判断是否使用海康视频服务器
- $is_hak = MineListExt::where('mine_id', $parent_id)->value('is_hak');
- //判断是否生成摄像头请求链接
- $camera_url = CameraList::where('id', $camera_id)->value('camera_url');
- if ($is_hak && !$camera_url) {
- //判断是否是mine配置文件的矿区
- $mine_res = DB::table('mine_list')->where('id',$parent_id)->get();
- if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('mine'))){
- //天地伟业使用easy_drawin获取rtsp
- $result = CameraServices::getRtspTianDi($camera_id,$parent_id);
- }else{
- //海康使用easy_drawin获取rtsp
- $result = CameraServices::getRtspHaiKang($camera_id, $parent_id);
- }
- } else {
- //硬盘录像机使用easy_drawin获取rtsp
- $result = CameraServices::getRtspYingPan($camera_id);
- }
- return self::successResponse($result);
- }
- /**
- * 作者: qiuzijian
- * 注释: 停止摄像头推流
- * @return \App\Http\Controllers\Api\JsonResponse
- */
- public function stopCamerasStream()
- {
- $camera_id = Input::get('camera_id', '');
- $result = CameraServices::stopCameraStream();
- return self::successResponse($result);
- }
- //回放列表
- public function getPlaybackList(){
- $camera_id = Input::get('camera_id', '');
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- if (!$camera_id) {
- $result['status'] = false;
- $result['msg'] = ApiEnum::STATUS_CODE_EMPTY;
- return $result;
- }
- $query = CameraList::where('id', $camera_id)->first();
- if (!$query) {
- $result['status'] = false;
- $result['msg'] = ApiEnum::NO_CAMERA_URL;
- return $result;
- }
- if($query->playback == 0){
- $result['status'] = false;
- $result['msg'] = ApiEnum::NO_SUPORT_PLAYBACK;
- return $result;
- }
- $playback = DB::table('playback')->where('camera_id',$query->id)->where('deleted_at',null)->get();
- if(count($playback)>0){
- for($i=0;$i<count($playback);$i++){
- $result['data'][$i]['title'] = $playback[$i]->title;
- $result['data'][$i]['start_time'] = $playback[$i]->start_time;
- $result['data'][$i]['end_time'] = $playback[$i]->end_time;
- $result['data'][$i]['camera_id'] = $playback[$i]->camera_id;
- }
- }else{
- $result['data'] = null;
- }
- return $result;
- }
- //回放URL
- public function getPlaybackUrl(){
- $time['start_time'] = explode(' ',Input::get('start_time', ''))[1];
- $time['end_time'] = explode(' ',Input::get('end_time', ''))[1];
- $camera_id = Input::get('camera_id', '');
- $start_time = Input::get('start_time', '');
- $end_time = Input::get('end_time', '');
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- if (!$camera_id || !$start_time || !$end_time) {
- $result['status'] = false;
- $result['msg'] = ApiEnum::STATUS_CODE_EMPTY;
- return $result;
- }
- $query = CameraList::where('id', $camera_id)->first();
- if (!$query) {
- $result['status'] = false;
- $result['msg'] = ApiEnum::NO_CAMERA_URL;
- return $result;
- }
- if($query->playback == 0){
- $result['status'] = false;
- $result['msg'] = ApiEnum::NO_SUPORT_PLAYBACK;
- return $result;
- }
- $degree = MineList::where('id', $query->mine_id)->value('degree');
- $degree = explode('|', $degree)[0];
- $mine_res = DB::table('mine_list')->where('id',$degree)->get();
- //判断摄像头是否是洗选中心的时间+34分钟
- if($mine_res[0]->slug == 'XiXuanZhongXin'){
- $start_time = date('Y-m-d H:i:s',strtotime($start_time.'+34 minutes'));
- $end_time = date('Y-m-d H:i:s',strtotime($end_time.'+34 minutes'));
- }
- $str = '.000+';
- $start_time = date('c', strtotime($start_time));//2022-07-14T08:00:00.000+08:00
- $start_time = explode('+',$start_time);
- $start_time = $start_time[0].$str.$start_time[1];
- $end_time = date('c', strtotime($end_time));
- $end_time = explode('+',$end_time);
- $end_time = $end_time[0].$str.$end_time[1];
- //判断是否在配置文件里,在的不用走ffmpeg
- if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('playback'))){
- $result = CameraServices::getPlaybackRtsp($camera_id,$start_time,$end_time);
- return self::successResponse($result);
- }else{
- $result = CameraServices::getPlaybackRtmp($camera_id,$start_time,$end_time,$time);
- return self::successResponse($result);
- }
- }
- //easydrawin回放URL
- public function getPlaybackUrlByEasy(){
- $time['start_time'] = explode(' ',Input::get('start_time', ''))[1];
- $time['end_time'] = explode(' ',Input::get('end_time', ''))[1];
- $camera_id = Input::get('camera_id', '');
- $start_time = Input::get('start_time', '');
- $end_time = Input::get('end_time', '');
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- if (!$camera_id || !$start_time || !$end_time) {
- $result['status'] = false;
- $result['msg'] = ApiEnum::STATUS_CODE_EMPTY;
- return $result;
- }
- $query = CameraList::where('id', $camera_id)->first();
- if (!$query) {
- $result['status'] = false;
- $result['msg'] = ApiEnum::NO_CAMERA_URL;
- return $result;
- }
- if($query->playback == 0){
- $result['status'] = false;
- $result['msg'] = ApiEnum::NO_SUPORT_PLAYBACK;
- return $result;
- }
- $degree = MineList::where('id', $query->mine_id)->value('degree');
- $degree = explode('|', $degree)[0];
- $mine_res = DB::table('mine_list')->where('id',$degree)->get();
- //判断摄像头是否是洗选中心的时间+34分钟
- if($mine_res[0]->slug == 'XiXuanZhongXin'){
- $start_time = date('Y-m-d H:i:s',strtotime($start_time.'+34 minutes'));
- $end_time = date('Y-m-d H:i:s',strtotime($end_time.'+34 minutes'));
- }
- $str = '.000+';
- $start_time = date('c', strtotime($start_time));//2022-07-14T08:00:00.000+08:00
- $start_time = explode('+',$start_time);
- $start_time = $start_time[0].$str.$start_time[1];
- $end_time = date('c', strtotime($end_time));
- $end_time = explode('+',$end_time);
- $end_time = $end_time[0].$str.$end_time[1];
- //判断是否在配置文件里,在的不用走ffmpeg
- if(isset($mine_res[0]->title) && in_array($mine_res[0]->title,config('playback'))){
- $result = CameraServices::getPlaybackRtsp($camera_id,$start_time,$end_time);
- return self::successResponse($result);
- }else{
- $result = CameraServices::getPlaybackByEasy($camera_id,$start_time,$end_time,$time);
- return self::successResponse($result);
- }
- }
- /**
- * 作者: qiuzijian
- * 注释: 获取编码设备信息
- * @return \App\Http\Controllers\Api\JsonResponse
- */
- public function getTranscodeInfo()
- {
- $parent_id = Input::get('parent_id', '');
- if (!$parent_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = CameraServices::getHaiKangTransCode($parent_id);
- return self::successResponse($result);
- }
- /**
- * 作者: qiuzijian
- * 注释: 获取大南湖摄像头列表
- * @return \App\Http\Controllers\Api\JsonResponse
- */
- public function getSouthLakeCamera()
- {
- $result = CameraServices::getLeChangeCamera();
- return self::successResponse($result);
- }
- public function pictureBase64(){
- $base64 = Input::get('base64', '');
- $camera_id = Input::get('camera_id', '');
- if (!$base64 || !$camera_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $data['base64'] = $base64;
- DB::table('camera_list')->where('id',$camera_id)->update($data);
- return self::successResponse();
- }
- public function test(){
- // header("Access-Control-Allow-Origin: *");
- $data = DB::table('goods')->get();
- return $data;
- }
- public function testadd(){
- // header("Access-Control-Allow-Origin: *");
- $res['good_name'] = Input::get('good_name', '');
- $res['good_url'] = 'images/1.jpg';
- $res['good_count'] = Input::get('good_count', '');
- $res['good_price'] = Input::get('good_price', '');
- $res['good_state'] = Input::get('good_state', '');
- DB::table('goods')->insert($res);
- return true;
- }
- public function testdel(){
- // header("Access-Control-Allow-Origin: *");
- DB::table('goods')->where('id',Input::get('id',''))->delete();
- return true;
- }
- public function testupdate(){
- // header("Access-Control-Allow-Origin: *");
- $res['good_name'] = Input::get('good_name', '');
- $res['good_url'] = 'images/1.jpg';
- $res['good_count'] = Input::get('good_count', '');
- $res['good_price'] = Input::get('good_price', '');
- $res['good_state'] = Input::get('good_state', '');
- DB::table('goods')->where('id',Input::get('id',''))->update($res);
- return true;
- }
- //值班信息
- public function dutyInformation(){
- $today = date('Y-m-d');
- $tomorrow = date("Y-m-d",strtotime("+1 day"));
- $result['today_zzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$today."' and type = 'zzb'");
- $result['today_fzzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$today."' and type = 'fz'");
- $result['tomorrow_zzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$tomorrow."' and type = 'zzb'");
- $result['tomorrow_fzzb'] = DB::connection('etl_zaoquan')->select("select * from news_duty_list where date ='".$tomorrow."' and type = 'fz'");
- return self::successResponse($result);
- }
- //分类列表
- public function typeList(){
- $result = $result = DB::connection('etl_zaoquan')->select("select type from news_column_list group by type");
- if(count($result) > 0){
- for($i=0;$i<count($result);$i++){
- if($result[$i]->type=="mkxw"){
- unset($result[$i]);
- $newObject = ['type' => 'mkxw','name'=>'煤矿新闻'];
- array_unshift($result, $newObject);
- }
- if($result[$i]->type == 'aqsc'){
- $result[$i]->name = '安全生产';
- }
- if($result[$i]->type == 'mkxw'){
- $result[$i]->name = '煤矿新闻';
- }
- if($result[$i]->type == 'zwbg'){
- $result[$i]->name = '政务办公';
- }
- if($result[$i]->type == 'djgz'){
- $result[$i]->name = '党建工作';
- }
- if($result[$i]->type == 'qygl'){
- $result[$i]->name = '企业管理';
- }
- if($result[$i]->type == 'jdgl'){
- $result[$i]->name = '机电管理';
- }
- if($result[$i]->type == 'scjsgl'){
- $result[$i]->name = '生产技术管理';
- }
- if($result[$i]->type == 'jjjc'){
- $result[$i]->name = '纪检监察';
- }
- if($result[$i]->type == 'zhzl'){
- $result[$i]->name = '综合治理';
- }
- if($result[$i]->type == 'jypx'){
- $result[$i]->name = '教育培训';
- }
- if($result[$i]->type == 'kwgk'){
- $result[$i]->name = '矿务公开';
- }
- }
- }
- return self::successResponse($result);
- }
- //文章列表
- public function articleList(Request $request){
- $params = $request->all();
- if (!isset($params['page_size'])) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!isset($params['page_num'])) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!isset($params['type'])) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $offset = $params['page_size'] * ($params['page_num'] - 1);
- $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);
- $pattern = '/<img(.*?)src=["\'](.*?)["\'](.*?)>/i';//图片
- $pattern2 = '/href="([^"]+)"/';//文件
- if(count($result) > 0){
- for($i=0;$i<count($result);$i++){
- //替换title_image
- $old_title_image = $result[$i]->title_image;
- $old_title_image_array = explode('/',$old_title_image);
- $old_img_path = $old_title_image_array[count($old_title_image_array)-1];
- $new_img_path_list = DB::connection('etl_zaoquan')->select("select * from news_img_list where img_name ='".$old_img_path."'");
- if(count($new_img_path_list) > 0){
- $result[$i]->main_img = $new_img_path_list[0]->new_name;
- }
- unset($result[$i]->title_image);
- $result[$i]->created_at = $result[$i]->create_time;
- unset($result[$i]->create_time);
- //替换text的图片
- preg_match_all($pattern, $result[$i]->text, $matches);
- foreach ($matches[2] as $index => $oldSrc) {
- $news_img_list = DB::connection('etl_zaoquan')->select("select * from news_img_list where img_name ='".basename($oldSrc)."'");
- if(count($news_img_list) > 0){
- $newSrc = $news_img_list[0]->new_name;
- $result[$i]->text = str_replace($oldSrc, $newSrc, $result[$i]->text);
- }
- }
- //替换text的文件
- preg_match_all($pattern2, $result[$i]->text, $matches2);
- foreach ($matches2[1] as $index => $oldSrc) {
- $news_file_list = DB::connection('etl_zaoquan')->select("select * from news_img_list where img_name ='".basename($oldSrc)."'");
- if(count($news_file_list) > 0){
- $newSrc = $news_file_list[0]->new_name;
- $result[$i]->text = str_replace($oldSrc, $newSrc, $result[$i]->text);
- }
- }
- }
- }
- return self::successResponse($result);
- }
- //文章图片上传至阿里云
- public function ossUrl(Request $request){
- $params = $request->all();
- if (!isset($params['url'])) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = $this->downloadFile($params['url']);
- return self::successResponse($result);
- }
- //下载文件
- public function downloadFile($file_path)
- {
- $rename = mt_rand(1111111,9999999);
- if (!$file_path) {
- return false;
- }
- set_time_limit(0);
- $ch = curl_init($file_path);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
- $rawdata = curl_exec ($ch);
- curl_close ($ch);
- $houzhui = explode('.',$file_path);
- $houzhui = '.'.$houzhui[count($houzhui)-1];
- // 使用中文文件名需要转码
- $fp = fopen(public_path() . '/filedownload/' . $rename.$houzhui, 'w');
- fwrite($fp, $rawdata);
- fclose($fp);
- $file_name = $rename;
- //上传文件
- $file_oss_path = $this->uploadFile($file_name,$houzhui);
- return $file_oss_path;
- }
- //上传文件
- public function uploadFile($file_name,$houzhui)
- {
- try{
- $oss = new OssClient(
- Config::get('filesystems.disks.oss_view.access_key'),
- Config::get('filesystems.disks.oss_view.secret_key'),
- Config::get('filesystems.disks.oss_view.endpoint')
- );
- $file_path = public_path() . '/filedownload/' . $file_name.$houzhui;
- $res = $oss->uploadFile(Config::get('filesystems.disks.oss_view.bucket'), $file_name.$houzhui, $file_path);
- } catch(\OssException $e) {
- printf(__FUNCTION__ . ": FAILED\n");
- printf($e->getMessage() . "\n");
- return;
- }
- if (isset($res['info']['url']) && $res['info']['url']) {
- unlink($file_path);
- return urldecode($res['info']['url']);
- } else {
- return false;
- }
- }
- //摄像头访问记录入库
- public function cameraRecordInsert(Request $request){
- $params = $request->all();
- // $opcDB = DB::connection('anning');
- // $dbResult = $opcDB->select('select * from uf_dwj_spjkymfw where ymid = 6224');
- if(isset($params['staff_num']) && isset($params['name']) && isset($params['department']) && isset($params['post']) && isset($params['camera_id']) && isset($params['start_time'])){
- $camera = DB::table('camera_list')->where('id',$params['camera_id'])->get();
- $mine = DB::table('mine_list')->where('id',$camera[0]->mine_id)->get();
- $degree = explode('|',$mine[0]->degree);
- $unit = DB::table('mine_list')->where('id',$degree[0])->get();
- $data['staff_num'] = $params['staff_num'];
- $data['name'] = $params['name'];
- $data['department'] = $params['department'];
- $data['post'] = $params['post'];
- $data['mine_id'] = $camera[0]->mine_id;
- $data['camera_id'] = $params['camera_id'];
- $data['camera_name'] = $camera[0]->camera_name;
- $data['unit_name'] = $unit[0]->title;
- if(isset($params['base64']) && $params['base64'] != null && $params['base64'] != ''){
- $data['base64'] = $params['base64'];
- }
- $data['start_time'] = date('Y-m-d').' '.$params['start_time'];
- // $data['start_time'] = date('Y-m-d').' '.$params['end_time'];
- $data['created_at'] = date('Y-m-d H:i:s');
- $data['updated_at'] = date('Y-m-d H:i:s');
- DB::table('camera_record')->insert($data);
- }
- }
- //摄像头访问记录列表
- public function cameraRecordList(Request $request){
- $params = $request->all();
- if (!isset($params['camera_id'])) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $camera_record = DB::table('camera_record')->where('camera_id',$params['camera_id'])->where('deleted_at',null)->orderBy('created_at','desc')->limit(20)->get();
- return self::successResponse($camera_record);
- }
- //摄像头下拉列表
- public function cameraSelect(Request $request){
- $result = '<select style="width:99%;" class="form-control" name="camera"><option value="0">-选择摄像头-</option>';
- $mine_list = DB::table('mine_list')->where('parent_id',6356)->where('deleted_at',null)->get();
- if(count($mine_list) > 0){
- for($i=0;$i<count($mine_list);$i++){
- $camera_list = DB::table('camera_list')->where('mine_id',$mine_list[$i]->id)->where('is_show',1)->where('deleted_at',null)->get();
- if(count($camera_list) > 0){
- $result = $result . '<optgroup label="' . $mine_list[$i]->title . '">';
- for($j=0;$j<count($camera_list);$j++){
- $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>';
- }
- $result = $result . '</optgroup>';
- }
- }
- }
- $result = $result . '</select>';
- return json_encode($result);
- }
- //摄像头信息
- public function cameraInfo(Request $request){
- $params = $request->all();
- $camera = DB::table('camera_list')->where('id',$params['camera_id'])->get();
- $result['id'] = $camera[0]->id;
- $result['camera_name'] = $camera[0]->camera_name;
- $result['camera_url'] = $camera[0]->camera_url;
- $result['camera_type'] = $camera[0]->camera_type;
- $result['cover_picture'] = $camera[0]->cover_picture;
- $result['parent_id'] = $camera[0]->mine_id;
- return $result;
- }
- //使用说明
- public function readme(Request $request){
- $params = $request->all();
- $result['coal_washery'] = DB::connection('task_xixuan')->table('xx_coal_washery')->orderBy('id')->get();
- $mine_list = DB::table('mine_list')->where('parent_id',6356)->where('deleted_at',null)->get();
- $result['camera_list'] = [];
- if(count($mine_list) > 0){
- for($i=0;$i<count($mine_list);$i++){
- $camera_list = DB::table('camera_list')->where('mine_id',$mine_list[$i]->id)->where('is_show',1)->where('deleted_at',null)->get();
- if(count($camera_list) > 0){
- $result['camera_list'][$i]['area'] = $mine_list[$i]->title;
- for($j=0;$j<count($camera_list);$j++){
- $result['camera_list'][$i]['camera_list'][$j] = $camera_list[$j]->id.':'.$camera_list[$j]->camera_name;
- }
- }
- }
- }
- return $result;
- }
- //主屏幕
- public function mainHome(Request $request){
- $gao = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', today())->where('risk_level',0)->count();
- $zhong = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', today())->where('risk_level',1)->count();
- $di = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', today())->where('risk_level',2)->count();
- $result = [
- [
- 'number' => $gao,
- 'unit' => '项',
- 'title' => '高风险作业',
- 'color' => '#DA0000'
- ],
- [
- 'number' => $zhong,
- 'unit' => '项',
- 'title' => '中风险作业',
- 'color' => '#FFBA00'
- ],
- [
- 'number' => $di,
- 'unit' => '项',
- 'title' => '低风险作业',
- 'color' => '#2BB200'
- ]
- ];
- return self::successResponse($result);
- }
- //风险作业占比
- public function riskWorkPercent(Request $request){
- $gao = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', today())->where('risk_level',0)->count();
- $zhong = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', today())->where('risk_level',1)->count();
- $di = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', today())->where('risk_level',2)->count();
- $result = [
- [
- 'value' => $gao,
- 'name' => '高风险',
- ],
- [
- 'value' => $zhong,
- 'name' => '中风险',
- ],
- [
- 'value' => $di,
- 'name' => '低风险',
- ]
- ];
- return self::successResponse($result);
- }
- //片区占比
- public function areaPercent(Request $request){
- $area = DB::connection('task_xixuan')->table('xx_area')->get();
- if(count($area) > 0){
- for($i=0;$i<count($area);$i++){
- $coal_washery_id_list = DB::connection('task_xixuan')->table('xx_coal_washery')->where('area_id',$area[$i]->id)->pluck('id');
- $result[$i]['value'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereIn('coal_washery_id',$coal_washery_id_list)->whereDate('optdt', today())->count();
- $result[$i]['name'] = $area[$i]->name;
- }
- }
- return self::successResponse($result);
- }
- //地图数据
- public function mapData(Request $request){
- $coal_washery = DB::connection('task_xixuan')->table('xx_coal_washery')->get();
- $coal_list = [
- '灵新洗煤厂'=>'linxing',
- '红柳洗煤厂'=>'hongliu',
- '枣泉洗煤厂'=>'zaoquan',
- '大武口洗煤厂'=>'dawukou',
- '金凤洗煤厂'=>'jinfeng',
- '检修车间'=>'jianxiuchejian',
- '太西洗煤厂'=>'taixi',
- '清水营洗煤厂'=>'qingshuiying',
- '梅花井洗煤厂'=>'meihuajing',
- '石槽村洗煤厂'=>'shicaocun',
- '双马洗煤厂'=>'shuangma',
- '羊场湾洗煤厂'=>'yangchangwan',
- '羊场湾二分区洗煤厂'=>'yangchangwanerfenqu'
- ];
- if(count($coal_washery) > 0){
- for($i=0;$i<count($coal_washery);$i++){
- if(array_key_exists($coal_washery[$i]->name, $coal_list)) {
- $slog = $coal_list[$coal_washery[$i]->name];
- $result[$slog]['title'] = $coal_washery[$i]->name;
- $result[$slog]['data'] = [
- [
- 'name' => '高风险作业',
- '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()
- ],
- [
- 'name' => '中风险作业',
- '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()
- ],
- [
- 'name' => '低风险作业',
- '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()
- ]
- ];
- }
- }
- }
- return self::successResponse($result);
- }
- //时间段作业数
- public function timeWorkCount(Request $request){
- $params = $request->all();
- if(isset($params['start_date']) && isset($params['end_date'])){
- $start_date = $params['start_date'];
- $end_date = $params['end_date'];
- }else{
- $start_date = date('Y-m-d', strtotime(date('Y-m-d') . ' -6 day'));
- $end_date = date('Y-m-d');
- }
- $current_date = $start_date;
- $i = 0;
- $result = [];
- $result['xAxis']['type'] = 'category';
- $result['xAxis']['data'] = [];
- $result['series'] = [
- [
- 'name' => '高风险作业',
- 'type' => 'bar',
- 'stack'=> 'bar_1',
- 'data' => [],
- 'itemStyle' => [
- 'color' => '#DA0000',
- 'borderRadius' => [10,10,10,10]
- ]
- ],
- [
- 'name' => '中风险作业',
- 'type' => 'bar',
- 'stack'=> 'bar_1',
- 'data' => [],
- 'itemStyle' => [
- 'color' => '#FFBA00',
- 'borderRadius' => [10,10,10,10]
- ]
- ],
- [
- 'name' => '低风险作业',
- 'type' => 'bar',
- 'stack'=> 'bar_1',
- 'data' => [],
- 'itemStyle' => [
- 'color' => '#2BB200',
- 'borderRadius' => [10,10,10,10]
- ]
- ]
- ];
- while ($current_date <= $end_date) {
- array_push($result['xAxis']['data'],$current_date);
- array_push($result['series'][0]['data'],DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $current_date)->where('risk_level',0)->count());
- array_push($result['series'][1]['data'],DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $current_date)->where('risk_level',1)->count());
- array_push($result['series'][2]['data'],DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $current_date)->where('risk_level',2)->count());
- $current_date = date('Y-m-d', strtotime($current_date . ' +1 day'));
- $i++;
- }
- return self::successResponse($result);
- }
- //时间段片区统计
- public function timeAreaTotal(Request $request){
- $params = $request->all();
- if (isset($params['area_id'])) {
- $area_id = $params['area_id'];
- }else{
- $area_id = 1;
- }
- if(isset($params['start_date']) && isset($params['end_date'])){
- $start_date = $params['start_date'];
- $end_date = $params['end_date'];
- }else{
- $start_date = date('Y-m-d', strtotime(date('Y-m-d') . ' -6 day'));
- $end_date = date('Y-m-d');
- }
- $coal_washery_id_list = DB::connection('task_xixuan')->table('xx_coal_washery')->where('area_id',$area_id)->pluck('id');
- $result = [];
- $current_date = $start_date;
- $i = 0;
- //当日片区数
- $result['data'] = [
- [
- '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(),
- 'unit' => '项',
- 'title' => '高风险作业',
- 'color' => '#DA0000'
- ],
- [
- '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(),
- 'unit' => '项',
- 'title' => '中风险作业',
- 'color' => '#FFBA00'
- ],
- [
- '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(),
- 'unit' => '项',
- 'title' => '低风险作业',
- 'color' => '#2BB200'
- ]
- ];
- $result['xAxis']['type'] = 'category';
- $result['xAxis']['data'] = [];
- $result['series'] = [
- [
- 'name' => '高风险作业',
- 'type' => 'line',
- 'data' => [],
- 'itemStyle' => [
- 'color' => '#DA0000',
- 'borderRadius' => [10,10,10,10]
- ]
- ],
- [
- 'name' => '中风险作业',
- 'type' => 'line',
- 'data' => [],
- 'itemStyle' => [
- 'color' => '#FFBA00',
- 'borderRadius' => [10,10,10,10]
- ]
- ],
- [
- 'name' => '低风险作业',
- 'type' => 'line',
- 'data' => [],
- 'itemStyle' => [
- 'color' => '#2BB200',
- 'borderRadius' => [10,10,10,10]
- ]
- ]
- ];
- while ($current_date <= $end_date) {
- array_push($result['xAxis']['data'],$current_date);
- 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());
- 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());
- 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());
- $current_date = date('Y-m-d', strtotime($current_date . ' +1 day'));
- $i++;
- }
- return self::successResponse($result);
- }
- //洗煤厂统计
- public function coalWasheryTotal(Request $request){
- $coal_washery = DB::connection('task_xixuan')->table('xx_coal_washery')->get();
- if(count($coal_washery) > 0){
- for($i=0;$i<count($coal_washery);$i++){
- $result[$i]['unit_name'] = $coal_washery[$i]->name;
- $result[$i]['data'] = [
- [
- 'label' => '高',
- '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(),
- 'color' => '#DA0000'
- ],
- [
- 'label' => '中',
- '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(),
- 'color' => '#FFBA00'
- ],
- [
- 'label' => '低',
- '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(),
- 'color' => '#2BB200'
- ],
- ];
- }
- }
- return self::successResponse($result);
- }
- //风险作业列表
- public function riskWorkList(Request $request){
- $params = $request->all();
- if(isset($params['type'])){
- $type = $params['type'];
- }else{
- $type = 0;
- }
- $coal_washery_list = DB::connection('task_xixuan')->table('xx_coal_washery')->get();
- if(count($coal_washery_list) > 0){
- for($i=0;$i<count($coal_washery_list);$i++){
- $result['unit_list'][$i]['text'] = $coal_washery_list[$i]->name;
- $result['unit_list'][$i]['value'] = $coal_washery_list[$i]->name;
- }
- }
- $risk = DB::connection('task_xixuan')->table('xx_risk_assignment');
- $risk = $risk->select('xx_risk_assignment.*','xx_coal_washery.name as coal_washery');
- $risk = $risk->leftJoin('xx_coal_washery','xx_coal_washery.id','=','xx_risk_assignment.coal_washery_id');
- $risk = $risk->whereDate('xx_risk_assignment.optdt', today());
- if(isset($params['id'])){
- $risk = $risk->where('xx_coal_washery.id',$params['id']);
- }
- $risk = $risk->where('risk_level',$type)->get();
- $result['data'] = [];
- if(count($risk) > 0){
- for($i=0;$i<count($risk);$i++){
- $result['data'][$i]['id'] = $risk[$i]->id;
- $result['data'][$i]['unit_name'] = $risk[$i]->coal_washery;
- $result['data'][$i]['place'] = $risk[$i]->work_location;
- $result['data'][$i]['content'] = $risk[$i]->risk_name;
- }
- }
- return self::successResponse($result);
- }
- //风险作业详情
- public function riskWorkDetail(Request $request){
- $params = $request->all();
- if (!isset($params['id'])) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $risk_type = ['高空坠落','起重伤害','触电','火灾','机械伤害','中毒和窒息'];
- $risk_level = ['高风险','中风险','低风险'];
- $risk = DB::connection('task_xixuan')->table('xx_risk_assignment')
- ->select('xx_risk_assignment.*','xx_coal_washery.name as coal_washery')
- ->leftJoin('xx_coal_washery','xx_coal_washery.id','=','xx_risk_assignment.coal_washery_id')
- ->where('xx_risk_assignment.id',$params['id'])->get();
- if(count($risk) > 0){
- $camera_info = explode('|',$risk[0]->camera_id);
- if($risk[0]->risk_type != '' && $risk[0]->risk_type !=null){
- $risk_type_value = $risk_type[$risk[0]->risk_type];
- }else{
- $risk_type_value = '';
- }
- $result['detail'] = [
- [
- 'label' => '风险类型:',
- 'value' => $risk_type_value
- ],
- [
- 'label' => '风险等级:',
- 'value' => $risk_level[$risk[0]->risk_level]
- ],
- [
- 'label' => '单位:',
- 'value' => $risk[0]->coal_washery
- ],
- [
- 'label' => '风险作业内容:',
- 'value' => $risk[0]->risk_name
- ],
- [
- 'label' => '人数:',
- 'value' => $risk[0]->work_num
- ],
- [
- 'label' => '地点:',
- 'value' => $risk[0]->work_location
- ],
- [
- 'label' => '现场负责人:',
- 'value' => $risk[0]->work_people
- ],
- [
- 'label' => '摄像头类型:',
- 'value' => CameraEnum::CAMERA_TYPE_EXCHANGE[$camera_info[3]]
- ],
- ];
- $camera_id = explode('|',$risk[0]->camera_id);
- $result['camera']['camera_id'] = $camera_id[0];
- $result['camera']['parent_id'] = $camera_id[1];
- }
- return self::successResponse($result);
- }
- //首頁信息
- public function taskHome(Request $request){
- $risk_type = ['高空坠落','起重伤害','触电','火灾','机械伤害','中毒和窒息'];
- $risk_level = ['高风险','中风险','低风险'];
- //高风险作业
- $gaofengxian = DB::connection('task_xixuan')->table('xx_risk_assignment')
- ->select('xx_risk_assignment.*','xx_coal_washery.name as coal_washery')
- ->leftJoin('xx_coal_washery','xx_coal_washery.id','=','xx_risk_assignment.coal_washery_id')
- ->whereDate('xx_risk_assignment.optdt', today())
- ->where('risk_level',0)->get();
- if(count($gaofengxian) > 0){
- for($i=0;$i<count($gaofengxian);$i++){
- if($gaofengxian[$i]->risk_type == ''){
- $gaofengxian[$i]->risk_type_name = '无';
- }else{
- $gaofengxian[$i]->risk_type_name = $risk_type[$gaofengxian[$i]->risk_type];
- }
- $camera_info = explode('|',$gaofengxian[$i]->camera_id);
- $gaofengxian[$i]->camera_type = CameraEnum::CAMERA_TYPE_EXCHANGE[$camera_info[3]];
- $gaofengxian[$i]->risk_level_name = $risk_level[$gaofengxian[$i]->risk_level];
- }
- }
- $result['gao_count'] = count($gaofengxian);
- $result['gao'] = $gaofengxian;
- //中风险作业
- $zhongfengxian = DB::connection('task_xixuan')->table('xx_risk_assignment')
- ->select('xx_risk_assignment.*','xx_coal_washery.name as coal_washery')
- ->leftJoin('xx_coal_washery','xx_coal_washery.id','=','xx_risk_assignment.coal_washery_id')
- ->whereDate('xx_risk_assignment.optdt', today())
- ->where('risk_level',1)->get();
- if(count($zhongfengxian) > 0){
- for($i=0;$i<count($zhongfengxian);$i++){
- if($zhongfengxian[$i]->risk_type == ''){
- $zhongfengxian[$i]->risk_type_name = '无';
- }else{
- $zhongfengxian[$i]->risk_type_name = $risk_type[$zhongfengxian[$i]->risk_type];
- }
- $camera_info = explode('|',$zhongfengxian[$i]->camera_id);
- $zhongfengxian[$i]->camera_type = CameraEnum::CAMERA_TYPE_EXCHANGE[$camera_info[3]];
- $zhongfengxian[$i]->risk_level_name = $risk_level[$zhongfengxian[$i]->risk_level];
- }
- }
- $result['zhong_count'] = count($zhongfengxian);
- $result['zhong'] = $zhongfengxian;
- //低风险作业
- $difengxian = DB::connection('task_xixuan')->table('xx_risk_assignment')
- ->select('xx_risk_assignment.*','xx_coal_washery.name as coal_washery')
- ->leftJoin('xx_coal_washery','xx_coal_washery.id','=','xx_risk_assignment.coal_washery_id')
- ->whereDate('xx_risk_assignment.optdt', today())
- ->where('risk_level',2)->get();
- if(count($difengxian) > 0){
- for($i=0;$i<count($difengxian);$i++){
- if($difengxian[$i]->risk_type == ''){
- $difengxian[$i]->risk_type_name = '无';
- }else{
- $difengxian[$i]->risk_type_name = $risk_type[$difengxian[$i]->risk_type];
- }
- $camera_info = explode('|',$difengxian[$i]->camera_id);
- $difengxian[$i]->camera_type = CameraEnum::CAMERA_TYPE_EXCHANGE[$camera_info[3]];
- $difengxian[$i]->risk_level_name = $risk_level[$difengxian[$i]->risk_level];
- }
- }
- $result['di_count'] = count($difengxian);
- $result['di'] = $difengxian;
- //片区作业数
- $area = DB::connection('task_xixuan')->table('xx_area')->get();
- $result['area_count'] = [];
- if(count($area) > 0){
- for($i=0;$i<count($area);$i++){
- $result['area_count'][$i]['name'] = $area[$i]->name;
- $coal_washery_id_list = DB::connection('task_xixuan')->table('xx_coal_washery')->where('area_id',$area[$i]->id)->pluck('id');
- $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();
- }
- }
- //洗煤厂作业
- $coal_washery = DB::connection('task_xixuan')->table('xx_coal_washery')->get();
- $result['coal_washery_work_count'] = [];
- if(count($coal_washery) > 0){
- for($i=0;$i<count($coal_washery);$i++){
- $result['coal_washery_work_count'][$i]['name'] = $coal_washery[$i]->name;
- $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();
- $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();
- $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();
- }
- }
- //7天作业数
- $result['seven_work_count'] = [];
- for($i=0;$i<7;$i++){
- $day = date('Y-m-d', strtotime('-'.$i.' day'));
- $result['seven_work_count'][$i]['date'] = $day;
- $result['seven_work_count'][$i]['gao'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $day)->where('risk_level',0)->count();
- $result['seven_work_count'][$i]['zhong'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $day)->where('risk_level',1)->count();
- $result['seven_work_count'][$i]['di'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $day)->where('risk_level',2)->count();
- }
- //7天片区作业数
- $result['seven_area_work_count'] = [];
- if(count($area) > 0){
- for($i=0;$i<count($area);$i++){
- $result['seven_area_work_count'][$i]['name'] = $area[$i]->name;
- $result['seven_area_work_count'][$i]['area_id'] = $area[$i]->id;
- for($j=0;$j<7;$j++){
- $day = date('Y-m-d', strtotime('-'.$j.' day'));
- $result['seven_area_work_count'][$i]['work'][$j]['date'] = $day;
- $coal_washery_id_list = DB::connection('task_xixuan')->table('xx_coal_washery')->where('area_id',$area[$i]->id)->pluck('id');
- $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();
- $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();
- $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();
- }
- }
- }
- return self::successResponse($result);
- }
- //首页作业查询
- public function workSearch(Request $request){
- $params = $request->all();
- if (!isset($params['start_date'])) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!isset($params['end_date'])) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = [];
- $start_date = $params['start_date'];
- $end_date = $params['end_date'];
- $current_date = $start_date;
- $i = 0;
- while ($current_date <= $end_date) {
- $result[$i]['date'] = $current_date;
- $result[$i]['gao'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $current_date)->where('risk_level',0)->count();
- $result[$i]['zhong'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $current_date)->where('risk_level',1)->count();
- $result[$i]['di'] = DB::connection('task_xixuan')->table('xx_risk_assignment')->whereDate('optdt', $current_date)->where('risk_level',2)->count();
- $current_date = date('Y-m-d', strtotime($current_date . ' +1 day'));
- $i++;
- }
- return self::successResponse($result);
- }
- //首页片区作业查询
- public function areaWorkSearch(Request $request){
- $params = $request->all();
- if (!isset($params['start_date'])) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!isset($params['end_date'])) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!isset($params['area_id'])) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $coal_washery_id_list = DB::connection('task_xixuan')->table('xx_coal_washery')->where('area_id',$params['area_id'])->pluck('id');
- $result = [];
- $start_date = $params['start_date'];
- $end_date = $params['end_date'];
- $current_date = $start_date;
- $i = 0;
- while ($current_date <= $end_date) {
- $result[$i]['date'] = $current_date;
- $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();
- $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();
- $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();
- $current_date = date('Y-m-d', strtotime($current_date . ' +1 day'));
- $i++;
- }
- return self::successResponse($result);
- }
- }
|