123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- <?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('xjdw1', $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('xjdw1', $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', 'lrr', 'dwmc')
- ->select(
- [
- DB::raw('DATE(lrsj) as lrdate'),
- 'lrr',
- 'dwmc'
- ]
- )
- ->get();
- dd($query);
- $data = [];
- foreach ($query as $key => $val) {
- if ($depart == 'all') {
- $wghgl = DB::connection('mysql_fwview')->table('uf_wghgl_new')
- ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
- ->where('lrr', $val->lrr)
- ->groupBy('xjdw')
- ->select('xjdw')
- ->get();
- $lastname = DB::connection('mysql_fwview')->table('hrmresource')
- ->where('id', $val->lrr)->value('lastname');
- foreach ($wghgl as $k => $v) {
- $allcount = DB::connection('mysql_fwview')->table('formtable_main_974')
- ->where('szxmc', $v->xjdw)->count();
- $detail = DB::connection('mysql_fwview')->table('uf_wghgl_new')
- ->where('xjdw', $v->xjdw)
- ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
- ->where('lrr', $val->lrr)->count();
- if ($detail >= $allcount) {
- $data[$val->lrr] = [
- 'department' => $val->dwmc,
- 'lastname' => $lastname,
- 'count' => isset($data[$val->lrr]['count']) ? $data[$val->lrr]['count'] + 1 : 0,
- ];
- } else {
- continue;
- }
- }
- } else {
- $allcount = DB::connection('mysql_fwview')->table('formtable_main_974')
- ->where('szxmc', $depart)->count();
- $detail = DB::connection('mysql_fwview')->table('uf_wghgl_new')
- ->where('xjdw', $depart)
- ->where(DB::raw('DATE(lrsj)'), $val->lrdate)
- ->where('lrr', $val->lrr)->count();
- if ($detail >= $allcount) {
- $lastname = DB::connection('mysql_fwview')->table('hrmresource')
- ->where('id', $val->lrr)->value('lastname');
- $data[$val->lrr] = [
- 'department' => $val->dwmc,
- 'lastname' => $lastname,
- 'count' => isset($data[$val->lrr]['count']) ? $data[$val->lrr]['count'] + 1 : 0,
- ];
- } else {
- continue;
- }
- }
- }
- $cmf_arr = array_column($data, 'count');
- array_multisort($cmf_arr, SORT_DESC, $data);
- $result['data'] = $data;
- return $result;
- }
- }
|