| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 |
- <?php
- /**
- * Created by PhpStorm.
- * User: qiuzijian
- * Date: 6/22/24
- * Time: 12:34 PM
- */
- namespace Modules\Admin\Services;
- use App\Enum\ApiEnum;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- use Modules\Admin\Entities\Menu;
- class ApiService{
- public function __construct()
- {
- }
- //网格化录入
- public static function addConition($params)
- {
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $insert = [
- 'lrr' => $params['lrr'],
- 'dwmc' => $params['dwmc'],
- 'xjdw' => $params['xjdw'],
- 'jcqy' => $params['jcqy'],
- 'jclx' => $params['jclx'],
- 'lrsj' => $params['lrsj'],
- 'jcwt' => $params['jcwt'],
- 'wtms' => $params['wtms'],
- 'dkpz' => $params['dkpz'],
- ];
- $res = DB::connection('mysql_fwview')->table('uf_wghgl_new')->insert($insert);
- return $result;
- }
- //网格化人员轨迹查询条件
- public static function getQueryConitions($date = '')
- {
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- if (!$date) {
- $date = date('Y-m-d', time());
- }
- $depart = DB::connection('mysql_fwview')->table('hrmdepartment')
- ->where('subcompanyid1', 49)
- ->where('departmentname', 'like', '%' . '洗煤厂')
- ->where('id', '!=', 1602)->get();
- $depart_arr = [];
- foreach ($depart as $key => $val) {
- $depart_name = str_replace('洗选中心', '', $val->DEPARTMENTNAME);
- $depart_arr[$key] = [
- 'name' => $depart_name,
- ];
- $query = DB::connection('mysql_fwview')->table('uf_wghgl_new')
- ->join('hrmresource', 'uf_wghgl_new.lrr', '=', 'hrmresource.id')
- ->where('xjdw', $depart_name)
- ->where('lrsj', 'like', '%' . $date . '%')
- ->groupBy('lrr')->select(
- [
- 'hrmresource.lastname as person_name',
- 'uf_wghgl_new.lrr as person_id'
- ]
- )->get();
- $query = json_decode($query);
- $depart_arr[$key]['person_list'] = $query;
- }
- $result['data'] = $depart_arr;
- return $result;
- }
- //网格化人员轨迹
- public static function getPersonTravel($person_id, $depart, $date = '')
- {
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- if (!$date) {
- $date = date('Y-m-d', time());
- }
- $res = [];
- $area_arr = [];
- $query = DB::connection('mysql_fwview')->table('uf_wghgl_new')
- ->where('lrr', $person_id)
- ->where('lrsj', 'like', '%' . $date . '%')
- ->where('xjdw', $depart)
- ->orderBy('lrsj', 'asc')->get();
- $query = json_decode($query);
- if ($query) {
- foreach ($query as $key => $val) {
- $area_arr[] = $val->jcqy;
- $res[] = [
- 'area' => $val->jcqy,
- 'date' => $val->lrsj,
- 'data_id' => $val->id,
- 'url' => '/mobilemode/formbasebrowserview.jsp?billid=' . $val->id . '&modeId=580&formId=-976',
- ];
- }
- $area_list = DB::connection('mysql_fwview')->table('formtable_main_974')
- ->whereNotIn('qymc', $area_arr)
- ->where('szxmc', $depart)->orderBy('areaid', 'asc')->get();
- foreach ($area_list as $area) {
- $res[] = [
- 'area' => $area->qymc,
- 'date' => '',
- 'data_id' => '',
- 'url' => '',
- ];
- }
- $result['data'] = $res;
- }
- return $result;
- }
- //网格化巡检记录查询条件
- public static function getResultConition()
- {
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $depart = DB::connection('mysql_fwview')->table('hrmdepartment')
- ->where('subcompanyid1', 49)
- ->where('departmentname', 'like', '%' . '洗煤厂')
- ->where('id', '!=', 1602)->get();
- $depart_arr = [];
- foreach ($depart as $key => $val) {
- $depart_name = str_replace('洗选中心', '', $val->DEPARTMENTNAME);
- $depart_arr[$key] = $depart_name;
- }
- $result['data'] = $depart_arr;
- return $result;
- }
- //网格化巡检记录查询
- public static function getResultRecord($depart = 'all', $date_type = 'week')
- {
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $query = DB::connection('mysql_fwview')->table('uf_wghgl_new');
- if ($depart != 'all') {
- $query = $query->where('xjdw', $depart);
- }
- if ($date_type == 'month') {
- $query = $query->where(DB::raw('MONTH(lrsj)'), DB::raw('MONTH(CURDATE())'));
- } else if ($date_type = 'quarter') {
- $query = $query->where(DB::raw('QUARTER(lrsj)'), DB::raw('QUARTER(CURDATE())'));
- } else {
- $query = $query->where(DB::raw('WEEK(lrsj)'), DB::raw('WEEK(CURDATE())'));
- }
- $query = $query->groupBy('lrdate', 'xjdw', 'lrr', 'dwmc')
- ->select(
- [
- DB::raw('DATE(lrsj) as lrdate'),
- 'xjdw',
- 'lrr',
- 'dwmc'
- ]
- )
- ->get();
- $data = [];
- $pie = [];
- foreach ($query as $key => $val) {
- $lastname = DB::connection('mysql_fwview')->table('hrmresource')
- ->where('id', $val->lrr)->value('lastname');
- $allcount = DB::connection('mysql_fwview')->table('formtable_main_974')
- ->where('szxmc', $val->xjdw)->count();
- $detail = DB::connection('mysql_fwview')->table('uf_wghgl_new')
- ->where('xjdw', $val->xjdw)
- ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
- ->where('lrr', $val->lrr)->count();
- if ($allcount <= 0) {
- continue;
- }
- if ($detail >= $allcount) {
- $data[$val->lrr] = [
- 'department' => $val->dwmc,
- 'lastname' => $lastname,
- 'person_id' => $val->lrr,
- 'count' => isset($data[$val->lrr]['count']) ? $data[$val->lrr]['count'] + 1 : 1,
- ];
- $pie[$val->lrr] = [
- 'name' => $lastname,
- 'value' => isset($data[$val->lrr]['value']) ? $data[$val->lrr]['value'] + 1 : 1,
- ];
- } else {
- continue;
- }
- }
- $data_arr = array_column($data, 'count');
- array_multisort($data_arr, SORT_DESC, $data);
- $pie_arr = array_column($pie, 'value');
- array_multisort($pie_arr, SORT_DESC, $pie);
- $result['data']['list'] = $data;
- $result['data']['pie'] = $pie;
- return $result;
- }
- //网格化巡检记录列表
- public static function getResultList($person_id, $depart = 'all', $date_type = 'week')
- {
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $query = DB::connection('mysql_fwview')->table('uf_wghgl_new')->where('lrr', $person_id);
- if ($depart != 'all') {
- $query = $query->where('xjdw', $depart);
- }
- if ($date_type == 'month') {
- $query = $query->where(DB::raw('MONTH(lrsj)'), DB::raw('MONTH(CURDATE())'));
- } else if ($date_type = 'quarter') {
- $query = $query->where(DB::raw('QUARTER(lrsj)'), DB::raw('QUARTER(CURDATE())'));
- } else {
- $query = $query->where(DB::raw('WEEK(lrsj)'), DB::raw('WEEK(CURDATE())'));
- }
- $query = $query->groupBy('lrdate', 'xjdw')
- ->select(
- [
- 'xjdw',
- DB::raw('DATE(lrsj) as lrdate'),
- ]
- )
- ->get();
- $data = [];
- foreach ($query as $key => $val) {
- $lastname = DB::connection('mysql_fwview')->table('hrmresource')
- ->where('id', $person_id)->value('lastname');
- $allcount = DB::connection('mysql_fwview')->table('formtable_main_974')
- ->where('szxmc', $val->xjdw)->count();
- $detail = DB::connection('mysql_fwview')->table('uf_wghgl_new')
- ->where('xjdw', $val->xjdw)
- ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
- ->where('lrr', $person_id)->count();
- if ($allcount <= 0) {
- continue;
- }
- if ($detail >= $allcount) {
- $data[] = [
- 'lastname' => $lastname,
- 'person_id' => $person_id,
- 'depart' => $val->xjdw,
- 'date' => $val->lrdate
- ];
- } else {
- continue;
- }
- }
- $data_arr = array_column($data, 'date');
- array_multisort($data_arr, SORT_DESC, $data);
- $result['data']['list'] = $data;
- return $result;
- }
- //网格化巡检记录列表明细
- public static function getResultDlist($person_id, $depart, $date)
- {
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $query = DB::connection('mysql_fwview')->table('uf_wghgl_new')
- ->join('hrmresource', 'uf_wghgl_new.lrr', '=', 'hrmresource.id')
- ->where('lrr', $person_id)
- ->where('xjdw', $depart)
- ->where('lrsj', 'like', $date . '%')
- ->orderBy('lrsj', 'desc')
- ->select(
- [
- 'uf_wghgl_new.id',
- 'lastname',
- 'jcqy',
- 'lrsj',
- ]
- )->get();
- $query = json_decode($query);
- $result['data'] = $query;
- return $result;
- }
- //网格化巡检记录明细
- public static function getResultDetails($id)
- {
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $query = DB::connection('mysql_fwview')->table('uf_wghgl_new')
- ->join('hrmresource', 'uf_wghgl_new.lrr', '=', 'hrmresource.id')
- ->where('uf_wghgl_new.id', $id)
- ->select(
- [
- 'lastname',
- 'dwmc',
- 'xjdw',
- 'jcqy',
- 'jclx',
- 'lrsj',
- 'jcwt',
- 'wtms',
- 'dkpz'
- ]
- )->get();
- $query = json_decode($query);
- $result['data'] = $query;
- return $result;
- }
- //网格化巡检记录
- public static function getFinalList($start_date, $end_date, $depart = '', $person = '')
- {
- $result['status'] = true;
- $result['msg'] = ApiEnum::RETURN_SUCCESS;
- $result['data'] = [];
- $query = DB::connection('mysql_fwview')->table('uf_wghgl_new');
- if ($start_date == $end_date) {
- $query = $query->where('lrsj', 'like', $start_date . '%');
- } else {
- $query = $query->where('lrsj', '>=', $start_date . ' 00:00:00')->where('lrsj', '<=', $end_date . ' 23:59:59');
- }
- if ($depart) {
- $query = $query->where('xjdw', $depart);
- }
- if ($person) {
- $person_id = DB::connection('mysql_fwview')->table('hrmresource')
- ->where('lastname', 'like', '%' . $person . '%')->value('id')->all();
- $query = $query->whereIn('lrr', $person_id);
- }
- $query = $query->orderBy('lrdate', 'desc')->groupBy('lrdate', 'xjdw', 'lrr')
- ->select(
- [
- DB::raw('DATE(lrsj) as lrdate'),
- 'xjdw',
- 'lrr'
- ]
- )
- ->get();
- $data = [];
- foreach ($query as $key => $val) {
- $lastname = DB::connection('mysql_fwview')->table('hrmresource')
- ->where('id', $val->lrr)->value('lastname');
- $allcount = DB::connection('mysql_fwview')->table('formtable_main_974')
- ->where('szxmc', $val->xjdw)->count();
- $detail = DB::connection('mysql_fwview')->table('uf_wghgl_new')
- ->where('xjdw', $val->xjdw)
- ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
- ->where('lrr', $val->lrr)->count();
- if ($allcount <= 0) {
- continue;
- }
- if ($detail >= $allcount) {
- $data[] = [
- 'depart' => $val->xjdw,
- 'lastname' => $lastname,
- 'person_id' => $val->lrr,
- 'date' => $val->lrdate,
- 'is_complete' => 1
- ];
- } else {
- $data[] = [
- 'depart' => $val->xjdw,
- 'lastname' => $lastname,
- 'person_id' => $val->lrr,
- 'date' => $val->lrdate,
- 'is_complete' => 0
- ];
- }
- }
- $result['data'] = $data;
- return $result;
- }
- }
|