| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076 |
- <?php
- /**
- * Created by PhpStorm.
- * User: qiuzijian
- * Date: 6/22/24
- * Time: 12:32 PM
- */
- namespace Modules\Admin\Http\Controllers\Api;
- use App\Enum\ApiEnum;
- use App\Http\Controllers\Api\BaseController;
- use App\Http\Controllers\Controller;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Input;
- use Modules\Admin\Entities\User;
- use Modules\Admin\Http\Requests\TokenRequest;
- use Modules\Admin\Services\ApiService;
- use Modules\Staff\Entities\Staff;
- use Symfony\Component\HttpFoundation\Response;
- class ApiController extends BaseController
- {
- //整改人列表
- public function zgrList(Request $request){
- $params = $request->all();
- if(!$params['xjdw']){
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $list = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->where('dwmc',$params['xjdw'])->get();
- if(count($list) > 0){
- for($i=0;$i<count($list);$i++){
- $result['data'][$i] = $list[$i]->zgrxm.'|'.$list[$i]->zgrgh;
- }
- }
- return $result;
- }
- //网格化录入
- public function addConition(Request $request)
- {
- $params = Input::get();
- if (!$params) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = ApiService::addConition($params);
- return self::successResponse($result);
- }
- //网格化整改
- public function editConition(Request $request){
- $params = Input::get();
- if (!$params) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = ApiService::editConition($params);
- return self::successResponse($result);
- }
- //网格化人员轨迹查询条件
- public function getQueryConition(Request $request)
- {
- $date = Input::get('date', '');
- if (!$date) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = ApiService::getQueryConitions($date);
- return self::successResponse($result);
- }
- //网格化人员轨迹
- public function getPersonTravel(Request $request)
- {
- $person_id = Input::get('person_id', '');
- $depart = Input::get('depart', '');
- $date = Input::get('date', '');
- if (!$person_id || !$depart) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = ApiService::getPersonTravel($person_id, $depart, $date);
- return self::successResponse($result);
- }
- //网格化巡检记录查询条件
- public function getResultConition()
- {
- $result = ApiService::getResultConition();
- return self::successResponse($result);
- }
- //网格化巡检记录查询
- public function getResultRecord()
- {
- $depart = Input::get('depart', 'all');
- $date_type = Input::get('date_type', 'week');
- $result = ApiService::getResultRecord($depart, $date_type);
- return self::successResponse($result);
- }
- //网格化巡检记录列表
- public function getResultList()
- {
- $person_id = Input::get('person_id', '');
- $depart = Input::get('depart', 'all');
- $date_type = Input::get('date_type', 'week');
- if (!$person_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = ApiService::getResultList($person_id, $depart, $date_type);
- return self::successResponse($result);
- }
- //网格化巡检记录列表明细
- public function getResultDlist()
- {
- $person_id = Input::get('person_id', '');
- $depart = Input::get('depart', '');
- $date = Input::get('date', '');
- if (!$person_id || !$depart || !$date) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = ApiService::getResultDlist($person_id, $depart, $date);
- return self::successResponse($result);
- }
- //网格化巡检记录明细
- public function getResultDetail()
- {
- $id = Input::get('id', '');
- if (!$id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = ApiService::getResultDetails($id);
- return self::successResponse($result);
- }
- //网格化巡检记录
- public function getFinalList()
- {
- $start_date = Input::get('start_date', '');
- $end_date = Input::get('end_date', '');
- $depart = Input::get('depart', '');
- $person = Input::get('person', '');
- if (!$start_date || !$end_date) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result = ApiService::getFinalList($start_date, $end_date, $depart, $person);
- return self::successResponse($result);
- }
- //网格化巡检权限
- public function getRole(){
- $staff_num = Input::get('staff_num', '');
- if (!$staff_num) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = 2;//无权限
- $people = DB::connection('mysql_fwe10')->table('uf_zhxx_qlczgry')->where('zgrgh',$staff_num)->where('is_delete',0)->get();
- if(count($people) > 0){
- $result['data'] = 1;//有权限
- }
- return self::successResponse($result);
- }
- //设备管理添加设备单位列表
- public function sbglUnitList(){
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $unit_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_qygl')->where('is_delete',0)->get();
- foreach($unit_list as $k => $v){
- $result['data'][] = [
- 'id' => $v->ID,
- 'qymc' => $v->qymc
- ];
- }
- return self::successResponse($result);
- }
- //设备管理添加设备负责人列表
- public function sbglPeopleList(){
- $unit_id = Input::get('unit_id', '');
- $type = Input::get('type', '');
- if (!$unit_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if($type == ''){
- $type = 0;
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- if($type == 0){//新设备负责人
- $name = 'xsbfzr';
- }elseif($type == 2){//待修负责人
- $name = 'dxfzr';
- }elseif($type == 3){//检修负责人
- $name = 'jxfzr';
- }elseif($type == 4){//检修验收负责人
- $name = 'jxysfzr';
- }elseif($type == 5){//鉴定识别(登记核实)负责人
- $name = 'dbffzr';
- }elseif($type == 6){//固定资产鉴定负责人
- $name = 'bffzr';
- }
- $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$unit_id)->where($name,0)->where('is_delete',0)->get();
- foreach($people_list as $k => $v){
- $result['data'][] = [
- 'id' => $v->ID,
- 'xm' => $v->xm
- ];
- }
- return self::successResponse($result);
- }
- //设备管理添加新设备
- public function sbglAdd(Request $request){
- $params = Input::get();
- if (!$params) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $id = mt_rand(pow(10, 18), pow(10, 18) + 999999999);
- $insert = [
- 'ID' => $id,
- 'FORM_DATA_ID' => $id,
- 'DATA_INDEX' => 0.0,
- 'CREATE_TIME' => date('Y-m-d H:i:s'),
- 'TENANT_KEY' => 't1zz9w8165',
- 'IS_DELETE' => 0,
- 'DELETE_TYPE' => 0,
- 'FT_STATUS' => 0,
- 'ssdw' => $params['qymc'],
- 'xsbdhfzr' => $params['xsbdhfzr'],
- 'sbmc' => $params['sbmc'],
- 'sbzp' => $params['sbzp'],
- 'rhzq' => $params['rhzq'],
- 'sbbh' => $params['sbbh'],
- 'ggxh' => $params['ggxh'],
- 'jscs' => $params['jscs'],
- 'sccj' => $params['sccj'],
- 'ccrq' => $params['ccrq'],
- 'dhrq' => $params['dhrq'],
- 'azrq' => $params['azrq'],
- 'syrq' => $params['syrq'],
- 'zyfssb' => $params['zyfssb'],
- 'ptjsj' => $params['ptjsj'],
- 'ylohq' => $params['ylohq'],
- 'ptqt' => $params['ptqt'],
- 'zypj' => $params['zypj'],
- 'bz' => $params['bz'],
- 'sbzt' => 0,
- 'sylx' => 4
- ];
- DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->insert($insert);
- return self::successResponse($result);
- }
- //设备管理设备详情
- public function sbglDetail(){
- $params = Input::get();
- if (!$params) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $data = DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl as sbgl')
- ->select('sbgl.*','qygl.qymc','qygl.wxlx','qygl.ID as qyid')
- ->leftJoin('uf_zhxx_sbgl_qygl as qygl','qygl.id','=','sbgl.ssdw')
- ->where('sbgl.ID',$params['id'])->get();
- // $sbzt = ['新设备到货验收中','完好','待修','检修中','检修验收中','鉴定识别(登记核实)中','已报废','代物资保管'];
- // $sylx = ['在用','备用','拆除','检修','闲置'];
- // $bflx = ['委外设备废品废件','废品','设备待报废'];
- foreach($data as $k=>$v){
- $v->xsbfzr_list = [];
- $v->dxfzr_list = [];
- $v->jxfzr_list = [];
- $v->dbffzr_list = [];
- $v->bffzr_list = [];
- if($v->sbzt == 0){//新设备负责人
- $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('xsbfzr',0)->where('is_delete',0)->get();
- foreach($people_list as $key => $val){
- $v->xsbfzr_list[] = [
- 'id' => $val->ID,
- 'xm' => $val->xm
- ];
- }
- }elseif($v->sbzt == 2){//待修负责人
- $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('dxfzr',0)->where('is_delete',0)->get();
- foreach($people_list as $key => $val){
- $v->dxfzr_list[] = [
- 'id' => $val->ID,
- 'xm' => $val->xm
- ];
- }
- }elseif($v->sbzt == 3){//检修负责人
- $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('jxfzr',0)->where('is_delete',0)->get();
- foreach($people_list as $key => $val){
- $v->jxfzr_list[] = [
- 'id' => $val->ID,
- 'xm' => $val->xm
- ];
- }
- }elseif($v->sbzt == 4){//检修验收负责人
- $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('jxysfzr',0)->where('is_delete',0)->get();
- foreach($people_list as $key => $val){
- $v->jxysfzr_list[] = [
- 'id' => $val->ID,
- 'xm' => $val->xm
- ];
- }
- }elseif($v->sbzt == 5){//鉴定识别(登记核实)负责人
- $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('dbffzr',0)->where('is_delete',0)->get();
- foreach($people_list as $key => $val){
- $v->dbffzr_list[] = [
- 'id' => $val->ID,
- 'xm' => $val->xm
- ];
- }
- }elseif($v->sbzt == 6){//固定资产鉴定负责人
- $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$v->ssdw)->where('bffzr',0)->where('is_delete',0)->get();
- foreach($people_list as $key => $val){
- $v->bffzr_list[] = [
- 'id' => $val->ID,
- 'xm' => $val->xm
- ];
- }
- }
- if($v->rhzq != null){
- $v->rhzq = $v->rhzq.'个月';
- }
- }
- $result['data'] = $data;
- return self::successResponse($result);
- }
- //设备管理润滑管理
- public function sbglRhList(){
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $current = time();// 获取当前时间戳
- $list = DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl as sbgl')
- ->select('sbgl.ID','sbgl.create_time','sbgl.sbmc','sbgl.scrhsj','sbgl.rhzq','qygl.qymc')
- ->leftJoin('uf_zhxx_sbgl_qygl as qygl','qygl.id','=','sbgl.ssdw')
- ->where('sbgl.rhzq','!=','')->where('sbgl.is_delete',0)->get()->toArray();
- foreach($list as $k => $v){
- if($v->scrhsj != null){
- $scrhsj = strtotime($v->scrhsj);
- $sjc = floor(($current - $scrhsj) / (60 * 60 * 24));
- $sjc = intval(round($sjc));
- $v->sjc = ($v->rhzq*30 - $sjc);
- }else{
- $create_time = strtotime($v->create_time);
- $sjc = floor(($current - $create_time) / (60 * 60 * 24));
- $sjc = intval(round($sjc));
- $v->sjc = ($v->rhzq*30 - $sjc);
- }
- }
- usort($list, function ($a, $b) {
- return $a->sjc <=> $b->sjc;
- });
- $result['data'] = $list;
- return self::successResponse($result);
- }
- //设备管理设备调拨
- public function sbglSbdb(){
- $params = Input::get();
- if (!$params) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $update = [
- 'ssdw' => $params['unit_id'],
- 'sbzt' => $params['sbzt'],
- 'sylx' => $params['sylx'],
- ];
- if(isset($params['sbbh'])){
- $update['sbbh'] = $params['sbbh'];
- }
- if(isset($params['bz'])){
- $update['bz'] = $params['bz'];
- }
- if($params['sbzt'] == 0){
- $update['xsbdhfzr'] = $params['fzr_id'];
- }
- if($params['sbzt'] == 2){
- $update['dxfzr'] = $params['fzr_id'];
- }
- if($params['sbzt'] == 3){
- $update['jxfzr'] = $params['fzr_id'];
- }
- if($params['sbzt'] == 4){
- $update['jxysfzr'] = $params['fzr_id'];
- }
- if($params['sbzt'] == 5){
- $update['dbffzr'] = $params['fzr_id'];
- }
- if($params['sbzt'] == 6){
- $update['bffzr'] = $params['fzr_id'];
- }
- DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->where('ID',$params['id'])->update($update);
- return self::successResponse($result);
- }
- //设备管理设备审核
- public function sbglSbsh(){
- $params = Input::get();
- if (!$params) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- if($params['action'] == 1){//删除设备
- DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->where('ID',$params['id'])->update(['is_delete'=>1]);
- return self::successResponse($result);
- }
- $update = [
- 'sbzt' => $params['sbzt'],
- 'sylx' => $params['sylx']
- ];
- if(isset($params['bz'])){
- $update['bz'] = $params['bz'];
- }
- if($params['sbzt'] == 3){
- $update['jxfzr'] = $params['fzr_id'];
- }
- if($params['sbzt'] == 4){
- $update['jxysfzr'] = $params['fzr_id'];
- }
- if($params['sbzt'] == 5){
- $update['dbffzr'] = $params['fzr_id'];
- }
- if($params['sbzt'] == 6){
- $update['bffzr'] = $params['fzr_id'];
- $update['bflx'] = $params['bflx'];
- }
- DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->where('ID',$params['id'])->update($update);
- return self::successResponse($result);
- }
- //设备管理权限
- public function sbglRole(){
- $id = Input::get('id', '');
- $staff_num = Input::get('staff_num', '');
- $unit_id = Input::get('unit_id', '');
- $type = Input::get('type', '');
- if (!$unit_id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!$staff_num) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!$type) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!$id && $type != 'sbgly') {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = 2;//无权限
- if($type == 'sbgly'){
- $people_list = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('ssdw',$unit_id)->where('gh',$staff_num)->where('sbgly',0)->where('is_delete',0)->get();
- if(count($people_list) > 0){
- $result['data'] = 1;//有权限
- }
- }else{
- $sb = DB::connection('mysql_fwe10')->table('uf_uf_zhxx_sbgl')->where('id',$id)->get();
- if($type == 'xsbdhfzr'){
- $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->xsbdhfzr)->get();
- if($people[0]->gh == $staff_num){
- $result['data'] = 1;
- }
- }
- if($type == 'dxfzr'){
- $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->dxfzr)->get();
- if($people[0]->gh == $staff_num){
- $result['data'] = 1;
- }
- }
- if($type == 'jxfzr'){
- $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->jxfzr)->get();
- if($people[0]->gh == $staff_num){
- $result['data'] = 1;
- }
- }
- if($type == 'jxysfzr'){
- $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->jxysfzr)->get();
- if($people[0]->gh == $staff_num){
- $result['data'] = 1;
- }
- }
- if($type == 'dbffzr'){
- $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->dbffzr)->get();
- if($people[0]->gh == $staff_num){
- $result['data'] = 1;
- }
- }
- if($type == 'bffzr'){
- $people = DB::connection('mysql_fwe10')->table('uf_zhxx_sbgl_rygl')->where('id',$sb[0]->bffzr)->get();
- if($people[0]->gh == $staff_num){
- $result['data'] = 1;
- }
- }
- }
- return self::successResponse($result);
- }
- //教育学习(洗选中的教育学习应用)
- // 学习效果检查统计表
- public function learningEffectCheck(Request $request)
- {
- $params = $request->all();
- if(isset($params['start_time']) && isset($params['end_time'])){
- $start_time = $params['start_time'];
- $end_time = $params['end_time'];
- }else{
- $start_time = date('Y-m-d 00:00:00');
- $end_time = date('Y-m-d 00:00:00', strtotime('+1 day'));
- }
- // 自评表数据
- $evaluate_data = DB::connection('mysql_fwe10')->table('uf_xx_zpb as t')
- ->select('t.dwmc as unitId','t.sgyy','t.sghg','t.sgcljg','t.xqjxjffcs','t.df','t1.dwmc')
- ->leftJoin('uf_xx_gxmcdw as t1', 't.dwmc', '=', 't1.id')
- ->whereBetween('t.create_time', [$start_time, $end_time])
- ->where('t.is_delete',0)
- ->where('t.delete_type',0)
- ->get();
- // 数据库查出来的数据进行处理
- $process_data = [];
- // 1. 提取所有单位id值
- $tmp = [];
- $index = 0;
- if(count($evaluate_data) > 0){
- for ($i = 0; $i < count($evaluate_data); $i++) {
- $process_data[$index]['unitId'] = $evaluate_data[$i]->unitId;
- $process_data[$index]['sgyy'] = $evaluate_data[$i]->sgyy;
- $process_data[$index]['sghg'] = $evaluate_data[$i]->sghg;
- $process_data[$index]['sgcljg'] = $evaluate_data[$i]->sgcljg;
- $process_data[$index]['xqjxjffcs'] = $evaluate_data[$i]->xqjxjffcs;
- $process_data[$index]['df'] = $evaluate_data[$i]->df;
- $process_data[$index]['dwmc'] = $evaluate_data[$i]->dwmc;
- $index++;
- $tmp[] = $evaluate_data[$i]->unitId;
- }
- }
- // 2. 去重并重置索引
- $unitId_List = array_values(array_unique($tmp));
- // 根据去重后的单位id给$evaluate_data中的数据分组
- $grouped = [];
- foreach ($process_data as $item) {
- $unitId = $item['unitId'];
- $grouped[$unitId][] = $item; // 按unitId值分组
- }
- $result = [];
- foreach ($unitId_List as $unitIdVar) {
- if (isset($grouped[$unitIdVar])) {
- $var1 = $grouped[$unitIdVar]; // 按uniqueBms顺序提取分组
- $result[] = $this->dataProcessing($var1);
- }
- }
- // 最后结果需要有个排名
- usort($result, function ($a, $b) {
- return $b['pjf'] <=> $a['pjf'];
- });
- $rank = 1;
- for ($i = 0; $i < count($result); $i++) {
- // 对于同一个 control_num 赋予相同的排名
- if ($i > 0 && $result[$i]['pjf'] == $result[$i - 1]['pjf']) {
- $result[$i]['rank'] = $result[$i - 1]['rank']; // 保持相同排名
- } else {
- $result[$i]['rank'] = $rank++; // 否则递增排名
- }
- }
- return self::successResponse($result);
- }
- // 对每组数据进行统计处理
- public function dataProcessing ($data = []): array
- {
- // 单位名称
- $unitName = '';
- // 检查人次
- $checkPeopleNum = count($data);
- // 事故原因
- $accidentCause = 0;
- // 事故后果
- $accidentConsequence = 0;
- // 事故处理结果
- $resultOfAccidentTreatment = 0;
- // 吸取教训/防范措施
- $preventiveMeasures = 0;
- // 最高分
- $theHighestScore = 0;
- // 最低分
- $theLowestScore = 100;
- // 平均分
- $averageScore = 0;
- foreach ($data as $item) {
- $accidentCause += $item['sgyy'];
- $accidentConsequence += $item['sghg'];
- $resultOfAccidentTreatment += $item['sgcljg'];
- $preventiveMeasures += $item['xqjxjffcs'];
- if ($theHighestScore < $item['df']) {
- $theHighestScore = $item['df'];
- }
- if ($theLowestScore > $item['df']) {
- $theLowestScore = $item['df'];
- }
- $averageScore += $item['df'];
- }
- $unitName = reset($data)['dwmc'];
- $accidentCause = round($accidentCause / $checkPeopleNum,2);
- $accidentConsequence = round($accidentConsequence / $checkPeopleNum,2);
- $resultOfAccidentTreatment = round($resultOfAccidentTreatment / $checkPeopleNum,2);
- $preventiveMeasures = round($preventiveMeasures / $checkPeopleNum,2);
- $averageScore = round($averageScore / $checkPeopleNum,2);
- $res = [
- 'dwmc' => $unitName,
- 'jcrc' => $checkPeopleNum,
- 'sgyy' => $accidentCause,
- 'sghg' => $accidentConsequence,
- 'sgcljg' => $resultOfAccidentTreatment,
- 'xqjxjffcs' => $preventiveMeasures,
- 'zgf' => $theHighestScore,
- 'zdf' => $theLowestScore,
- 'pjf' => $averageScore
- ];
- return $res;
- }
- //巡检轨迹
- public function getGuiji(){
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $list1 = [];
- $date = Input::get('date', '');
- $depart = Input::get('depart', '');
- $lrr = Input::get('lrr', '');
- if (!$date) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!$depart) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!$lrr) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $list = DB::connection('mysql_fwe10')->table('uf_zhxx_qlcxjjl')->where('lrsj','like','%'.$date.'%')->where('xjdw',$depart)->where('lrr',$lrr)->orderBy('create_time')->get();
- if(count($list) > 0){
- for($i=0;$i<count($list);$i++){
- $list1[$i]['lat'] = $list[$i]->lat;
- $list1[$i]['lng'] = $list[$i]->lng;
- $list1[$i]['title'] = $list[$i]->xjqy;
- $list1[$i]['id'] = $list[$i]->ID;
- }
- }
- //去重
- $serialized = array_map('serialize', $list1);
- $unique = array_unique($serialized);
- $list2 = array_map('unserialize', $unique);
- //取中心点
- $total = array_reduce($list2, function($carry, $item) {
- $carry['lat'] += (float)$item['lat'];
- $carry['lng'] += (float)$item['lng'];
- return $carry;
- }, ['lat' => 0, 'lng' => 0]);
- $avgLat = $total['lat'] / count($list2);
- $avgLng = $total['lng'] / count($list2);
- $result['list1'] = $list1;
- $result['list2'] = $list2;
- $result['lat'] = $avgLat;
- $result['lng'] = $avgLng;
- return self::successResponse($result);
- }
- //获取视频信息
- public function getVideoInfo()
- {
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $spid = Input::get('spid', '');
- if (!$spid) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $res = DB::connection('mysql_fwe10')->table('uf_zhxx_aqsc_aqjsjy')->where('ID',$spid)->get();
- if(count($res) > 0){
- $result['data']['title'] = $res[0]->bt;
- $result['data']['url'] = 'http://10.186.134.157:20600/api/file/preview?fileId='.$res[0]->spsc.'&module=document&type=video&cusMenuId=8442742813977835931&urlPageTitle=5Liq5Lq65paH5qGj5bqT&docId=8445065037895701229&editLinkType=editPage&customParam=%7B%22fromPCDoc%22%3A1%7D';
- }
- return self::successResponse($result);
- }
- //问卷调查题目
- public function getTopicList()
- {
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $res = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_tgl')->select('id','tmlx','xztm','tktm','jdtm','xxa','xxb','xxc','xxd','xxe')->where('is_delete',0)->orderBy('tmlx')->orderBy('create_time')->get();
- if(count($res) > 0){
- for($i=0;$i<count($res);$i++){
- if($res[$i]->tmlx == '3'){//简答题
- $res[$i]->tm = $res[$i]->jdtm;
- }elseif($res[$i]->tmlx == '2'){//填空题
- $res[$i]->tm = $res[$i]->tktm;
- }else{//选择题
- $res[$i]->tm = $res[$i]->xztm;
- }
- }
- }
- $result['data'] = $res;
- return self::successResponse($result);
- }
- //问卷调查统计
- public function getTopicStatic()
- {
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data']['title'] = '洗选中心'.date("Y").'年员工思想状况调查问卷';
- $jid = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_jgl')->where('is_delete',0)->orderBy('create_time','desc')->limit(1)->pluck('ID')[0];
- $tgl_list = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_tgl')->where('is_delete',0)->orderBy('tmlx')->orderBy('create_time')->get();
- $statis_list = [];
- if(count($tgl_list) > 0){
- for($i=0;$i<count($tgl_list);$i++){
- $statis_list[$i]['id'] = $tgl_list[$i]->ID;
- $statis_list[$i]['tmlx'] = $tgl_list[$i]->tmlx;
- if($tgl_list[$i]->tmlx == 0){//单选题
- $statis_list[$i]['title'] = $tgl_list[$i]->xztm;
- $statis_list[$i]['type'] = '单选题';
- $statis_list[$i]['a'] = $tgl_list[$i]->xxa;
- $statis_list[$i]['b'] = $tgl_list[$i]->xxb;
- $statis_list[$i]['c'] = $tgl_list[$i]->xxc;
- $statis_list[$i]['d'] = $tgl_list[$i]->xxd;
- $statis_list[$i]['e'] = $tgl_list[$i]->xxe;
- $statis_list[$i]['a_num'] = 0;
- $statis_list[$i]['b_num'] = 0;
- $statis_list[$i]['c_num'] = 0;
- $statis_list[$i]['d_num'] = 0;
- $statis_list[$i]['e_num'] = 0;
- $statis_list[$i]['num'] = 0;
- }
- if($tgl_list[$i]->tmlx == 1){//多选题
- $statis_list[$i]['title'] = $tgl_list[$i]->xztm;
- $statis_list[$i]['type'] = '多选题';
- $statis_list[$i]['a'] = $tgl_list[$i]->xxa;
- $statis_list[$i]['b'] = $tgl_list[$i]->xxb;
- $statis_list[$i]['c'] = $tgl_list[$i]->xxc;
- $statis_list[$i]['d'] = $tgl_list[$i]->xxd;
- $statis_list[$i]['e'] = $tgl_list[$i]->xxe;
- $statis_list[$i]['a_num'] = 0;
- $statis_list[$i]['b_num'] = 0;
- $statis_list[$i]['c_num'] = 0;
- $statis_list[$i]['d_num'] = 0;
- $statis_list[$i]['e_num'] = 0;
- $statis_list[$i]['num'] = 0;
- }
- if($tgl_list[$i]->tmlx == 2){//填空题
- $statis_list[$i]['title'] = $tgl_list[$i]->tktm;
- }
- if($tgl_list[$i]->tmlx == 3){//简答题
- $statis_list[$i]['title'] = $tgl_list[$i]->jdtm;
- }
- }
- }
- $dtqk_list = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_dtqk')->select('da','tid')->where('jid',$jid)->where('is_delete',0)->get();
- $id_list = array_column($statis_list, 'id');
- if(count($dtqk_list) > 0){
- for($i=0;$i<count($dtqk_list);$i++){
- $key = array_search($dtqk_list[$i]->tid, $id_list);
- if($statis_list[$key]['tmlx'] == 0){//单选
- if($dtqk_list[$i]->da == 'A'){
- $statis_list[$key]['a_num']++;
- }
- if($dtqk_list[$i]->da == 'B'){
- $statis_list[$key]['b_num']++;
- }
- if($dtqk_list[$i]->da == 'C'){
- $statis_list[$key]['c_num']++;
- }
- if($dtqk_list[$i]->da == 'D'){
- $statis_list[$key]['d_num']++;
- }
- if($dtqk_list[$i]->da == 'E'){
- $statis_list[$key]['e_num']++;
- }
- }
- if($statis_list[$key]['tmlx'] == 1){//多选
- $da = explode(',',$dtqk_list[$i]->da);
- for($j=0;$j<count($da);$j++){
- if($da[$j] == 'A'){
- $statis_list[$key]['a_num']++;
- }
- if($da[$j] == 'B'){
- $statis_list[$key]['b_num']++;
- }
- if($da[$j] == 'C'){
- $statis_list[$key]['c_num']++;
- }
- if($da[$j] == 'D'){
- $statis_list[$key]['d_num']++;
- }
- if($da[$j] == 'E'){
- $statis_list[$key]['e_num']++;
- }
- }
- }
- }
- }
- if(count($statis_list) > 0){
- $num = $statis_list[0]['a_num'] + $statis_list[0]['b_num'] + $statis_list[0]['c_num'] + $statis_list[0]['d_num'] + $statis_list[0]['e_num'];
- for($i=0;$i<count($statis_list);$i++){
- if($statis_list[$i]['tmlx'] == 0){
- $statis_list[$i]['num'] = $num;
- $statis_list[$i]['a_percent'] = number_format(($statis_list[$i]['a_num']/$num)*100, 2).'%';
- $statis_list[$i]['b_percent'] = number_format(($statis_list[$i]['b_num']/$num)*100, 2).'%';
- $statis_list[$i]['c_percent'] = number_format(($statis_list[$i]['c_num']/$num)*100, 2).'%';
- $statis_list[$i]['d_percent'] = number_format(($statis_list[$i]['d_num']/$num)*100, 2).'%';
- $statis_list[$i]['e_percent'] = number_format(($statis_list[$i]['e_num']/$num)*100, 2).'%';
- }
- if($statis_list[$i]['tmlx'] == 1){
- $statis_list[$i]['num'] = $num;
- $n = $statis_list[$i]['a_num']+$statis_list[$i]['b_num']+$statis_list[$i]['c_num']+$statis_list[$i]['d_num']+$statis_list[$i]['e_num'];
- $statis_list[$i]['a_percent'] = number_format(($statis_list[$i]['a_num']/$n)*100, 2).'%';
- $statis_list[$i]['b_percent'] = number_format(($statis_list[$i]['b_num']/$n)*100, 2).'%';
- $statis_list[$i]['c_percent'] = number_format(($statis_list[$i]['c_num']/$n)*100, 2).'%';
- $statis_list[$i]['d_percent'] = number_format(($statis_list[$i]['d_num']/$n)*100, 2).'%';
- $statis_list[$i]['e_percent'] = number_format(($statis_list[$i]['e_num']/$n)*100, 2).'%';
- }
- }
- }
- $result['data']['list'] = $statis_list;
- return self::successResponse($result);
- }
- //问卷调查单题列表
- public function getTopicTestList()
- {
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $id = Input::get('id', '');
- if (!$id) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $t = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_tgl')->where('ID',$id)->get();
- $list = DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_dtqk')->where('tid',$id)->where('is_delete',0)->orderBy('create_time')->pluck('da');
- if($t[0]->tmlx == 2){//填空
- $result['data']['title'] = $t[0]->tktm;
- }
- if($t[0]->tmlx == 3){//简答
- $result['data']['title'] = $t[0]->jdtm;
- }
- $result['data']['list'] = [];
- if(count($list) > 0){
- for($i=0;$i<count($list);$i++){
- if($list[$i] != '无' && $list[$i] != '没有'){
- array_push($result['data']['list'],$list[$i]);
- }
- }
- }
- return self::successResponse($result);
- }
- //问卷调查提交
- public function submitTopic(Request $request)
- {
- $params = $request->all();
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $list = $params['answer'];
- if(count($list) > 0){
- for($i=0;$i<count($list);$i++){
- $id = mt_rand(pow(10, 18), pow(10, 18) + 999999999);
- if (is_array($list[$i]['value'])) {
- $value = implode(',', $list[$i]['value']);
- } else {
- $value = $list[$i]['value'];
- }
- $insert = [
- 'ID' => $id,
- 'FORM_DATA_ID' => $id,
- 'DATA_INDEX' => 0.0,
- 'CREATE_TIME' => date('Y-m-d H:i:s'),
- 'TENANT_KEY' => 't1zz9w8165',
- 'IS_DELETE' => 0,
- 'DELETE_TYPE' => 0,
- 'FT_STATUS' => 0,
- 'jid' => $params['jid'],
- 'da' => $value,
- 'tid' => $list[$i]['id'],
- 'xm' => $params['xm'],
- 'gh' => $params['gh']
- ];
- DB::connection('mysql_fwe10')->table('uf_zhxx_wjdc_dtqk')->insert($insert);
- }
- }
- return self::successResponse($result);
- }
- //腾讯地图逆地址解析
- public function positionGeocoder(){
- $lat = Input::get('lat', '');//纬度
- $lng = Input::get('lng', '');//经度
- if (!$lat) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- if (!$lng) {
- return self::errorResponse(ApiEnum::STATUS_CODE_EMPTY);
- }
- $gps = $lat.','.$lng;
- $sig = '/ws/geocoder/v1?key='.env('TX_KEY').'&location='.$gps.env('TX_SK');
- $sig = md5($sig);
- $params = [
- 'location' => $gps,
- 'key' => env('TX_KEY'),
- 'sig' => $sig
- ];
- $result = $this->sendRequest("https://apis.map.qq.com/ws/geocoder/v1",$params);
- $position = '';
- if(isset($result['result']['formatted_addresses']['recommend'])){
- $position = $result['result']['formatted_addresses']['recommend'];
- }
- return self::successResponse($position);
- }
- //腾讯位置接口服务
- public function sendRequest($url, $params) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url . "?" . http_build_query($params));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- $response = curl_exec($ch);
- curl_close($ch);
- return json_decode($response, true);
- }
- }
|